Skip to content

Commit

Permalink
Fix for auto update procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
Metalios committed May 24, 2020
1 parent 2961508 commit df473b9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Base/Base/Master_Classes/MidsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public static class MidsContext
public const string AppName = "Mids' Reborn";
public const int AppMajorVersion = 2;
public const int AppMinorVersion = 7;
public const int AppBuildVersion = 1;
public const int AppRevisionVersion = 20;
public const string AppAssemblyVersion = "2.7.1.20";
public const int AppBuildVersion = 2;
public const int AppRevisionVersion = 10;
public const string AppAssemblyVersion = "2.7.2.10";
public static readonly Version AppVersion = new Version(major: AppMajorVersion, minor: AppMinorVersion, build: AppBuildVersion, revision: AppRevisionVersion);

public const string Title = "Mids' Reborn : Hero Designer";
Expand Down
13 changes: 9 additions & 4 deletions Base/Files.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

public static class Files
Expand Down Expand Up @@ -61,8 +62,10 @@ static string FNameJsonConfig
{
get
{
var fp = Path.Combine(Application.StartupPath, Path.Combine("Data", JsonFileConfig));
return Debugger.IsAttached ? SearchUp("Data", fp) : fp;
var asmLOC = Assembly.GetExecutingAssembly().Location;
var dirLOC = $"{Directory.GetParent(asmLOC)}\\Data\\";
//var fp = Path.Combine(Application.StartupPath, Path.Combine("Data", JsonFileConfig));
return $"{dirLOC}{JsonFileConfig}";

}
}
Expand Down Expand Up @@ -102,10 +105,12 @@ internal static string GetConfigFilename(bool forceMhd)
{
try
{
var asmLOC = Assembly.GetExecutingAssembly().Location;
var dirLOC = $"{Directory.GetParent(asmLOC)}\\Data\\";
if (!forceMhd && File.Exists(FNameJsonConfig)) return FNameJsonConfig;
if (File.Exists(FNameConfig) || !File.Exists(OS.GetApplicationPath() + "Data\\Config.mhd"))
if (File.Exists(FNameConfig) || !File.Exists(dirLOC + "Config.mhd"))
return FNameConfig;
return OS.GetApplicationPath() + "Data\\Config.mhd";
return $"{dirLOC}Config.mhd";
}
catch
{
Expand Down
40 changes: 34 additions & 6 deletions Hero Designer/Forms/frmUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ public void BeginInstall()
}
public void InstallUpdate(string updateType)
{
var asmLOC = Assembly.GetExecutingAssembly().Location;
var dirLOC = $"{Directory.GetParent(asmLOC)}";
ctlProgressBar2.Value = 0;
switch (updateType)
{
case "App":
ctlProgressBar2.StatusText = $"Installing: Mids {VersionText}";
foreach (var filename in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.dll"))
foreach (var filename in Directory.GetFiles(dirLOC, "*.dll"))
{
File.Move(filename, $"{filename}.bak");
}
Expand Down Expand Up @@ -137,11 +139,13 @@ private void zipExtractor_DoWork(object sender, DoWorkEventArgs e)
{
ZProgress = new Progress<ZipProgress>();
ZProgress.ProgressChanged += Report;
TempFile = $"{Path.GetTempPath()}\\MidsTemp\\{VersionText}.zip";
TempFile = $"{Path.GetTempPath()}MidsTemp\\{VersionText}.zip";
var loc = Assembly.GetExecutingAssembly().Location;
var dirloc = Directory.GetParent(loc);
var dirLOC = Directory.GetParent(loc);
var dirTmp = $"{Path.GetTempPath()}MidsTemp\\";
using ZipArchive zip = ZipFile.OpenRead(TempFile);
zip.ExtractToDirectory(dirloc.ToString(), ZProgress, true);
zip.ExtractToDirectory(dirTmp, ZProgress, true);
zip.ExtractToDirectory(dirLOC.ToString(), null, true);
}

private void Report(object sender, ZipProgress zipProgress)
Expand All @@ -162,17 +166,41 @@ private void zipExtractor_ProgressChanged(object sender, ProgressChangedEventArg
ctlProgressBar2.Text = $@"{ctlProgressBar2.StatusText}";
}

public static void TransferFiles(string sourcePath, string destinationPath)
{
foreach (var file in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories))
{
var dirInfo = new DirectoryInfo(file);
var fileInfo = new FileInfo(file);
var parentDir = dirInfo.Parent?.Name;
if (parentDir == "MidsTemp")
{
var destFile = $"{destinationPath}\\{fileInfo.Name}";
File.Copy(fileInfo.FullName, destFile, true);
}
/*else
{
var subPath = $"{destinationPath}\\{parentDir}\\{fileInfo.Name}";
File.Copy(fileInfo.FullName, subPath, true);
}*/
}
}

private void zipExtractor_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
var asmLOC = Assembly.GetExecutingAssembly().Location;
var dirLOC = $"{Directory.GetParent(asmLOC)}";
ctlProgressBar2.Value = ctlProgressBar2.Maximum;
ctlProgressBar2.Text = "Installation Complete!";
ctlProgressBar2.StatusText = "Install Complete!";
var completed = MessageBox.Show(@"The update was successfully applied, Mids will now restart.",
@"Update Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (completed == DialogResult.OK)
{
File.Delete(TempFile);
Directory.Delete($"{Path.GetTempPath()}\\MidsTemp\\");
TransferFiles($"{Path.GetTempPath()}MidsTemp\\", dirLOC);
Thread.Sleep(2000);
Directory.Delete($"{Path.GetTempPath()}MidsTemp\\", true);
File.Delete($"{dirLOC}\\{VersionText}.zip");
Application.Restart();
}
}
Expand Down
8 changes: 6 additions & 2 deletions Hero Designer/clsXMLUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public static void CheckUpdate()
MessageBox.Show($"{e.Message}\n{e.StackTrace}", "Error");
}
}
var cDbVersion = DatabaseAPI.Database.Version;
if (AppVersion > MidsContext.AppVersion)
{
if (!Mandatory)
Expand All @@ -113,8 +114,7 @@ public static void CheckUpdate()
Update(UpdateType.App, AppVersion.ToString(), ChangeLog);
}
}
var cDbVersion = DatabaseAPI.Database.Version;
if (DbVersion > cDbVersion && AppVersion < MidsContext.AppVersion)
else if (DbVersion > cDbVersion && AppVersion < MidsContext.AppVersion)
{
if (!Mandatory)
{
Expand All @@ -129,6 +129,10 @@ public static void CheckUpdate()
Update(UpdateType.Database, DbVersion.ToString(CultureInfo.InvariantCulture), ChangeLog);
}
}
else
{
MessageBox.Show($@"No update is available at this time.", @"Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

public static void Update(Enum type, string updateVersion, string changeLog)
Expand Down
8 changes: 4 additions & 4 deletions Hero Designer/clsZip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public ZipProgress(int total, int processed, string currentItem)

public static class MyZipFileExtensions
{
public static void ExtractToDirectory(this ZipArchive source, string destinationDirectoryName, IProgress<ZipProgress> progress)
/*public static void ExtractToDirectory(this ZipArchive source, string destinationDirectoryName, IProgress<ZipProgress> progress)
{
ExtractToDirectory(source, destinationDirectoryName, progress, overwrite: false);
}
}*/

public static void ExtractToDirectory(this ZipArchive source, string destinationDirectoryName, IProgress<ZipProgress> progress, bool overwrite)
{
Expand All @@ -53,7 +53,7 @@ public static void ExtractToDirectory(this ZipArchive source, string destination
throw new IOException("File is extracting to outside of the folder specified.");

var zipProgress = new ZipProgress(source.Entries.Count, count, entry.FullName);
progress.Report(zipProgress);
progress?.Report(zipProgress);

if (Path.GetFileName(fileDestinationPath).Length == 0)
{
Expand All @@ -69,7 +69,7 @@ public static void ExtractToDirectory(this ZipArchive source, string destination
// If it is a file:
// Create containing directory:
Directory.CreateDirectory(Path.GetDirectoryName(fileDestinationPath));
entry.ExtractToFile(fileDestinationPath, overwrite: overwrite);
entry.ExtractToFile(fileDestinationPath, overwrite);
}
}
}
Expand Down

0 comments on commit df473b9

Please sign in to comment.