Skip to content

Commit

Permalink
Update update system
Browse files Browse the repository at this point in the history
  • Loading branch information
NessieHax committed Jun 25, 2024
1 parent 07d319b commit 69ff1f2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 58 deletions.
8 changes: 3 additions & 5 deletions PCK-Studio-Updater/API/GithubUpdateDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public bool IsUpdateAvailable(Version productVersion)
{
Debug.WriteLine("Release Product ver.: " + latestReleaseVersion);
Debug.WriteLine("Current Product ver.: " + productVersion);
return latestReleaseVersion.CompareTo(productVersion) > 0;
return latestReleaseVersion.CompareTo(productVersion) >= 0;
}

public bool IsUpdateAvailable(string productVersion)
Expand Down Expand Up @@ -101,10 +101,9 @@ private void GetLatestRelease(bool prerelease)

private void EmptyDirectory(DirectoryInfo directory)
{
string appname = Assembly.GetExecutingAssembly().GetName().Name;
foreach (FileInfo file in directory.GetFiles())
{
if (Path.GetFileNameWithoutExtension(file.Name) != appname && file.Name != "update.zip")
if (Path.GetFileNameWithoutExtension(file.Name) != _updateParams.TargetExecutableName && file.Name != "update.zip")
file.Delete();
}
foreach (DirectoryInfo subDirectory in directory.GetDirectories())
Expand All @@ -118,15 +117,14 @@ public void DownloadTo(DirectoryInfo directory)
if (latestFetchedRelease.Assets?.Count > 0)
{
var asset = latestFetchedRelease.Assets[0];
string zipFilePath = Path.Combine(directory.FullName, "update.zip");
string zipFilePath = Path.Combine(directory.FullName, asset.Name);
using(var zipFileStream = File.OpenWrite(zipFilePath))
{
DownloadAsset(asset, zipFileStream);
}
Debug.WriteLine("Download Complete", category: nameof(GithubUpdateDownloader));
EmptyDirectory(directory);
UnpackZip(zipFilePath);
File.Delete(zipFilePath);
downloadDirectory = directory;
}
}
Expand Down
6 changes: 2 additions & 4 deletions PCK-Studio/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2480,12 +2480,10 @@ private void addANIMEntryToolStripMenuItem1_Click(object sender, EventArgs e)

private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Program.Updater.IsUpdateAvailable(Application.ProductVersion))
if (Program.UpdateToLatest("Would you like to download it?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, DialogResult.Yes))
{
Program.UpdateToLatest("Would you like to download it?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, DialogResult.Yes);
return;
MessageBox.Show(this, "Already up to date.", "No update available");
}
MessageBox.Show(this, "Already up to date.", "No update available");
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
7 changes: 3 additions & 4 deletions PCK-Studio/PckStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,9 @@
<PackageReference Include="AnimatedGif">
<Version>1.0.5</Version>
</PackageReference>
<PackageReference Include="Autoupdater.NET.Official">
<Version>1.9.1</Version>
</PackageReference>
<PackageReference Include="Costura.Fody">
<Version>5.8.0-alpha0098</Version>
<IncludeAssets>compile; runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down Expand Up @@ -716,10 +719,6 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PCK-Studio-Updater\PCK-Studio-Updater.csproj">
<Project>{5B223556-15B9-41DA-AA0B-5E7F45E743BF}</Project>
<Name>PCK-Studio-Updater</Name>
</ProjectReference>
<ProjectReference Include="..\Vendor\OMI-Lib\OMI Filetypes Library\OMI Filetype Library.csproj">
<Project>{693AEBC1-293D-4DF0-BCAE-26A1099FE7BB}</Project>
<Name>OMI Filetype Library</Name>
Expand Down
32 changes: 7 additions & 25 deletions PCK-Studio/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using PckStudio.Internal.Misc;
using PckStudio.Internal;
using PckStudio.Properties;
using PCKStudio_Updater;
using PckStudio.Internal.App;


Expand All @@ -21,16 +20,6 @@ static class Program
internal static readonly string AppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Application.ProductName);
internal static readonly string AppDataCache = Path.Combine(AppData, "cache");

private static readonly GithubParams UpdateParams = new GithubParams(
Path.GetDirectoryName(ProjectUrl.AbsolutePath).Replace("\\", ""),
Path.GetFileName(ProjectUrl.AbsolutePath),
Application.ProductName,
Settings.Default.UsePrerelease,
new Regex("(\\*|\\d+(\\.\\d+){0,3}(\\.\\*)?)")
);
internal static readonly IUpdateDownloader Updater = new GithubUpdateDownloader(UpdateParams);


internal static MainForm MainInstance { get; private set; }

/// <summary>
Expand All @@ -54,21 +43,14 @@ static void Main(string[] args)
Application.Run(MainInstance);
}

[Conditional("NDEBUG")]
internal static void UpdateToLatest(string message, MessageBoxButtons buttons, MessageBoxIcon icon, DialogResult dialogResult)
internal static bool UpdateToLatest(string message, MessageBoxButtons buttons, MessageBoxIcon icon, DialogResult dialogResult)
{
bool updateAvailable = Updater.IsUpdateAvailable(Application.ProductVersion);
if (updateAvailable && MessageBox.Show(
MainInstance ?? null,
"New update available.\n" +
message,
"Update Available",
buttons, icon, MessageBoxDefaultButton.Button1) == dialogResult)
{
Updater.DownloadTo(new DirectoryInfo(Application.StartupPath));
Updater.Launch();
Application.Exit();
}
#if NDEBUG
AutoUpdaterDotNET.AutoUpdater.Start($"{ProjectUrl}/Version.xml");
return true;
#else
return false;
#endif
}
}
}
20 changes: 0 additions & 20 deletions PCK_Studio.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OMI Filetype Library", "Ven
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpMss32", "Vendor\SharpMss32\SharpMss32\SharpMss32.csproj", "{E8D0B671-3AB1-48B6-A767-58DF67BD5D11}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCK-Studio-Updater", "PCK-Studio-Updater\PCK-Studio-Updater.csproj", "{5B223556-15B9-41DA-AA0B-5E7F45E743BF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Beta|Any CPU = Beta|Any CPU
Expand Down Expand Up @@ -80,24 +78,6 @@ Global
{E8D0B671-3AB1-48B6-A767-58DF67BD5D11}.Release|x64.Build.0 = Release|Any CPU
{E8D0B671-3AB1-48B6-A767-58DF67BD5D11}.Release|x86.ActiveCfg = Release|Any CPU
{E8D0B671-3AB1-48B6-A767-58DF67BD5D11}.Release|x86.Build.0 = Release|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Beta|Any CPU.ActiveCfg = Debug|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Beta|Any CPU.Build.0 = Debug|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Beta|x64.ActiveCfg = Debug|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Beta|x64.Build.0 = Debug|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Beta|x86.ActiveCfg = Debug|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Beta|x86.Build.0 = Debug|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Debug|x64.ActiveCfg = Debug|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Debug|x64.Build.0 = Debug|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Debug|x86.ActiveCfg = Debug|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Debug|x86.Build.0 = Debug|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Release|Any CPU.Build.0 = Release|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Release|x64.ActiveCfg = Release|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Release|x64.Build.0 = Release|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Release|x86.ActiveCfg = Release|Any CPU
{5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 6 additions & 0 deletions Version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "7.0.0.0",
"url": "https://github.com/PhoenixARC/-PCK-Studio/releases/tag/v7.0.0.0/PCK-Studio.zip",
"changelog": "https://github.com/PhoenixARC/-PCK-Studio/releases",
"mandatory": false
}

0 comments on commit 69ff1f2

Please sign in to comment.