Skip to content

Commit

Permalink
Fixed update logic
Browse files Browse the repository at this point in the history
Fixed update logic to handle old version executables and renamed them to consistent format
  • Loading branch information
nezhatweaks authored Oct 19, 2024
1 parent 80e4023 commit 194c29e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Assets/latest_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.1.0
0.2.2.0
2 changes: 1 addition & 1 deletion NZTS App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<UseWPF>true</UseWPF>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AssemblyVersion>0.2.1.0</AssemblyVersion>
<FileVersion>0.2.1.0</FileVersion>
<FileVersion>0.2.2.0</FileVersion>
<PackageIcon>nezhalogo12.2.jpg</PackageIcon>
<ApplicationIcon>nezhalogo12.2.3.ico</ApplicationIcon>
</PropertyGroup>
Expand Down
20 changes: 12 additions & 8 deletions SettingsUserControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,18 @@ private async Task CheckForUpdates()
return;
}

string oldExecutablePath = Path.Combine(appDirectory, "NZTS_App_v0.1.0.exe");
// Current executable name
string currentExecutablePath = Path.Combine(appDirectory, "NZTS APP.exe");
string newZipPath = Path.Combine(appDirectory, $"NZTS_APP_v{latestVersionStr}.zip");

if (File.Exists(oldExecutablePath))
if (File.Exists(currentExecutablePath))
{
string backupDirectory = Path.Combine(appDirectory, "Backup");
Directory.CreateDirectory(backupDirectory);

// Backup the old executable
string backupExecutablePath = Path.Combine(backupDirectory, $"NZTS_App_v0.1.0_backup_{DateTime.Now:yyyyMMddHHmmss}.exe");
File.Copy(oldExecutablePath, backupExecutablePath, true);
// Backup the current executable
string backupExecutablePath = Path.Combine(backupDirectory, $"NZTS_APP_backup_{DateTime.Now:yyyyMMddHHmmss}.exe");
File.Copy(currentExecutablePath, backupExecutablePath, true);

// Download the versioned ZIP file
byte[] zipFileData = await client.GetByteArrayAsync(string.Format(NewZipUrlTemplate, latestVersionStr));
Expand All @@ -76,8 +77,8 @@ private async Task CheckForUpdates()
// Extract the ZIP file
ZipFile.ExtractToDirectory(newZipPath, appDirectory, true); // true to overwrite existing files

// Delete the old version executable
File.Delete(oldExecutablePath); // Delete NZTS_App_v0.1.0.exe
// Delete the current version executable
File.Delete(currentExecutablePath); // Delete NZTS APP.exe

// Optionally delete the ZIP file after extraction
File.Delete(newZipPath);
Expand All @@ -86,7 +87,8 @@ private async Task CheckForUpdates()
}
else
{
MessageBox.Show("Old version executable not found. Please install the application first.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
// Log or ignore the absence of the current executable
Console.WriteLine("Current version executable not found, proceeding without backup.");
}
}
else
Expand All @@ -100,5 +102,7 @@ private async Task CheckForUpdates()
MessageBox.Show($"Error checking for updates: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}


}
}

0 comments on commit 194c29e

Please sign in to comment.