Skip to content

Commit

Permalink
Revert "Revert "Update""
Browse files Browse the repository at this point in the history
This reverts commit a566bc1.
  • Loading branch information
sefinek24 committed Mar 12, 2024
1 parent a566bc1 commit d3f315c
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 45 deletions.
6 changes: 3 additions & 3 deletions Stella.Launcher/1. Stella Mod Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<FileVersion>8.0.0.0</FileVersion>
<Version>8.0.0.0</Version>
<AssemblyVersion>7.9.7.0</AssemblyVersion>
<FileVersion>7.9.7.0</FileVersion>
<Version>7.9.7.0</Version>
<StartupObject>StellaModLauncher.Program</StartupObject>
<ApplicationIcon>data\images\icons\nahida.ico</ApplicationIcon>
<BaseOutputPath>..\Build\</BaseOutputPath>
Expand Down
57 changes: 32 additions & 25 deletions Stella.Launcher/Forms/Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,35 @@ private async void Main_Shown(object sender, EventArgs e)

// Check for updates
Stages.UpdateStage(7, "Checking for updates...");

// Detect resource path
string? resourcesPath = null;
using (RegistryKey? key = Registry.CurrentUser.OpenSubKey(Program.RegistryPath))
{
if (key != null) resourcesPath = key.GetValue("ResourcesPath") as string;
}

if (string.IsNullOrEmpty(resourcesPath))
{
Program.Logger.Error("Path of the resources was not found. Is null or empty");
MessageBox.Show(Resources.Default_ResourceDirNotFound, Program.AppNameVer, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

if (!Directory.Exists(resourcesPath))
{
Program.Logger.Error($"Directory with the resources '{resourcesPath}' was not found");
MessageBox.Show(string.Format(Resources.Default_Directory_WasNotFound, resourcesPath), Program.AppNameVer, MessageBoxButtons.OK, MessageBoxIcon.Error);
}

if (string.IsNullOrEmpty(resourcesPath) || !Directory.Exists(resourcesPath))
{
_ = Cmd.Execute(new Cmd.CliWrap { App = Program.ConfigurationWindow });
Application.Exit();
}

ResourcesPath = resourcesPath;

// Updates
int found = await CheckForUpdates.Analyze().ConfigureAwait(true);
switch (found)
{
Expand All @@ -317,6 +346,9 @@ private async void Main_Shown(object sender, EventArgs e)
return;
}

MessageBox.Show($@"OK: {found}");


// Updated?
int updatedLauncher = Program.Settings.ReadInt("Updates", "UpdateAvailable", 0);
string oldVersion = Program.Settings.ReadString("Updates", "OldVersion");
Expand All @@ -334,31 +366,6 @@ private async void Main_Shown(object sender, EventArgs e)


Stages.UpdateStage(8, "Checking required data...");
string? resourcesPath = null;
using (RegistryKey? key = Registry.CurrentUser.OpenSubKey(Program.RegistryPath))
{
if (key != null) resourcesPath = key.GetValue("ResourcesPath") as string;
}

if (string.IsNullOrEmpty(resourcesPath))
{
Program.Logger.Error("Path of the resources was not found. Is null or empty");
MessageBox.Show(Resources.Default_ResourceDirNotFound, Program.AppNameVer, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

if (!Directory.Exists(resourcesPath))
{
Program.Logger.Error($"Directory with the resources '{resourcesPath}' was not found");
MessageBox.Show(string.Format(Resources.Default_Directory_WasNotFound, resourcesPath), Program.AppNameVer, MessageBoxButtons.OK, MessageBoxIcon.Error);
}

if (string.IsNullOrEmpty(resourcesPath) || !Directory.Exists(resourcesPath))
{
_ = Cmd.Execute(new Cmd.CliWrap { App = Program.ConfigurationWindow });
Application.Exit();
}

ResourcesPath = resourcesPath;

// Check Genshin Stella Mod.exe
if (!File.Exists(Run.GsmPath) && !Debugger.IsAttached)
Expand Down
11 changes: 11 additions & 0 deletions Stella.Launcher/Scripts/Forms/MainForm/Labels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,15 @@ public static void HideProgressbar(string? successText, bool error)
TaskbarProgress.SetProgressValue(100);
TaskbarProgress.SetProgressState(TaskbarProgress.Flags.Error);
}

public static void FailedToLoad()
{
Default._version_LinkLabel!.Text = @"v-.-.-.-";
Default._checkForUpdates_LinkLabel!.Text = @"---";
Default._progressBar1!.Value = 100;
Default._preparingPleaseWait!.Text = @"Canceled.";

TaskbarProgress.SetProgressState(TaskbarProgress.Flags.Paused);
TaskbarProgress.SetProgressValue(100);
}
}
29 changes: 15 additions & 14 deletions Stella.Launcher/Scripts/Remote/CheckForUpdates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace StellaModLauncher.Scripts.Remote;

internal static class CheckForUpdates
{
public static int FoundUpdates = 0;

public static async Task<int> Analyze()
{
Default._checkForUpdates_LinkLabel!.LinkColor = Color.White;
Expand Down Expand Up @@ -47,7 +49,7 @@ public static async Task<int> Analyze()
{
Default.UpdateIsAvailable = true;

NormalRelease.Run(remoteDbLauncherVersion, remoteLauncherDate, res.Launcher!.Beta);
await NormalRelease.Run(remoteDbLauncherVersion, remoteLauncherDate, res.Launcher!.Beta).ConfigureAwait(true);
return 2;
}

Expand Down Expand Up @@ -76,7 +78,7 @@ public static async Task<int> Analyze()
Default.UpdateIsAvailable = true;

DateTime remoteResourcesDate = DateTime.Parse(res.Resources.Date!, null, DateTimeStyles.RoundtripKind).ToUniversalTime().ToLocalTime();
DownloadResources.Run(data?.Version!, remoteDbResourcesVersion, remoteResourcesDate);
await DownloadResources.Run(data?.Version!, remoteDbResourcesVersion, remoteResourcesDate).ConfigureAwait(true);
return 1;
}
}
Expand Down Expand Up @@ -117,26 +119,25 @@ public static async Task<int> Analyze()
if (Secret.IsStellaPlusSubscriber)
{
int found = await CheckForUpdatesOfBenefits.Analyze().ConfigureAwait(true);
if (found == 1)
MessageBox.Show($@"CheckForUpdatesOfBenefits: {found}");
switch (found)
{
Default._checkForUpdates_LinkLabel.LinkColor = Color.Cyan;
Default._checkForUpdates_LinkLabel.Text = Resources.Default_UpdatingBenefits;
Default._updateIco_PictureBox!.Image = Resources.icons8_download_from_the_cloud;
return found;
case 1:
Default._checkForUpdates_LinkLabel.LinkColor = Color.Cyan;
Default._checkForUpdates_LinkLabel.Text = Resources.Default_UpdatingBenefits;
Default._updateIco_PictureBox!.Image = Resources.icons8_download_from_the_cloud;
return found;
case 666:
Labels.FailedToLoad();
return 666;
}
}


// == Banned? ==
if (res!.IsBanned)
{
Default._version_LinkLabel!.Text = @"v-.-.-.-";
Default._checkForUpdates_LinkLabel!.Text = @"---";
Default._progressBar1!.Value = 100;
Default._preparingPleaseWait!.Text = @"Canceled.";

TaskbarProgress.SetProgressState(TaskbarProgress.Flags.Paused);
TaskbarProgress.SetProgressValue(100);
Labels.FailedToLoad();

new Banned().Show();

Expand Down
2 changes: 1 addition & 1 deletion Stella.Launcher/Scripts/Remote/NormalRelease.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal static class NormalRelease
public static readonly string SetupPathExe = Path.Combine(Path.GetTempPath(), "Stella-Mod-Update.exe");
private static readonly string DownloadUrl = Debugger.IsAttached ? "http://127.0.0.1:5180/Stella-Mod-Setup.exe" : "https://github.com/sefinek24/Genshin-Impact-ReShade/releases/latest/download/Stella-Mod-Setup.exe";

public static async void Run(string? remoteVersion, DateTime remoteVerDate, bool beta)
public static async Task Run(string? remoteVersion, DateTime remoteVerDate, bool beta)
{
// 1
Default._version_LinkLabel!.Text = $@"v{Program.AppFileVersion} → v{remoteVersion}";
Expand Down
2 changes: 1 addition & 1 deletion Stella.Launcher/Scripts/Remote/StellaResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class DownloadResources
private const string DownloadUrl = "https://github.com/sefinek24/Genshin-Stella-Resources/releases/latest/download/resources.zip";
private static string? _stellaResZip;

public static async void Run(string? localResVersion, string? remoteResVersion, DateTime remoteResDate)
public static async Task Run(string? localResVersion, string? remoteResVersion, DateTime remoteResDate)
{
// 1
Default._version_LinkLabel!.Text = $@"v{localResVersion} → v{remoteResVersion}";
Expand Down
16 changes: 15 additions & 1 deletion Stella.Launcher/Scripts/StellaPlus/CheckForUpdatesOfBenefits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@ internal static class CheckForUpdatesOfBenefits
{
public static async Task<int> Analyze()
{
BenefitVersions? remoteVersions = await GetVersions().ConfigureAwait(true);
if (!Directory.Exists(Default.ResourcesPath))
{
Program.Logger.Error($"Default.ResourcesPath not exists: {Default.ResourcesPath}");

MessageBox.Show("The resources folder was not found. It probably does not exist, or the program encountered some issue in locating it.\n\nContact the developer if you need assistance.",
Program.AppNameVer, MessageBoxButtons.OK, MessageBoxIcon.Error);
return 666;
}

BenefitVersions? remoteVersions = await GetVersions().ConfigureAwait(true);

// 3DMigoto
string migotoVerPath = Path.Combine(Default.ResourcesPath!, "3DMigoto", "3dmigoto-version.json");
Program.Logger.Info($"Checking: {migotoVerPath}");
if (File.Exists(migotoVerPath))
{
string migotoJson = await File.ReadAllTextAsync(migotoVerPath).ConfigureAwait(true);
Expand All @@ -42,6 +51,7 @@ public static async Task<int> Analyze()

// Mods for 3DMigoto
string modsVerPath = Path.Combine(Default.ResourcesPath!, "3DMigoto", "mods-version.json");
Program.Logger.Info($"Checking: {modsVerPath}");
if (File.Exists(modsVerPath))
{
string modsJson = await File.ReadAllTextAsync(modsVerPath).ConfigureAwait(true);
Expand Down Expand Up @@ -70,6 +80,7 @@ public static async Task<int> Analyze()

// Addons
string addonsVersionPath = Path.Combine(Default.ResourcesPath!, "ReShade", "Addons", "version.json");
Program.Logger.Info($"Checking: {addonsVersionPath}");
if (File.Exists(addonsVersionPath))
{
string addonsJson = await File.ReadAllTextAsync(addonsVersionPath).ConfigureAwait(true);
Expand All @@ -95,6 +106,7 @@ public static async Task<int> Analyze()

// Presets
string presetsVersionPath = Path.Combine(Default.ResourcesPath!, "ReShade", "Presets", "3. Stella Mod Plus", "version.json");
Program.Logger.Info($"Checking: {presetsVersionPath}");
if (File.Exists(presetsVersionPath))
{
string presetsJson = await File.ReadAllTextAsync(presetsVersionPath).ConfigureAwait(true);
Expand Down Expand Up @@ -123,6 +135,7 @@ public static async Task<int> Analyze()

// Shaders
string shadersVersionPath = Path.Combine(Default.ResourcesPath!, "ReShade", "Shaders", "version.json");
Program.Logger.Info($"Checking: {shadersVersionPath}");
if (File.Exists(shadersVersionPath))
{
string shadersJson = await File.ReadAllTextAsync(shadersVersionPath).ConfigureAwait(true);
Expand All @@ -148,6 +161,7 @@ public static async Task<int> Analyze()

// Cmd files
string cmdVersionPath = Path.Combine(Program.AppPath, "data", "cmd", "patrons", "version.json");
Program.Logger.Info($"Checking: {cmdVersionPath}");
if (File.Exists(cmdVersionPath))
{
string cmdJson = await File.ReadAllTextAsync(cmdVersionPath).ConfigureAwait(true);
Expand Down

0 comments on commit d3f315c

Please sign in to comment.