Skip to content

Commit

Permalink
updater works again after UI split
Browse files Browse the repository at this point in the history
  • Loading branch information
EpsiRho committed Apr 30, 2024
1 parent 1cd9f7f commit 95a7a11
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Code/Melon/DisplayClasses/SettingsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,12 @@ private static void CheckForUpdates()
UseShellExecute = false
};
Process.Start(processInfo);

File.Create($"{AppDomain.CurrentDomain.BaseDirectory}/GoAway.sdrq");
Environment.Exit(0);
}
catch (Exception)
{
MelonUI.ClearConsole();
Console.WriteLine(StringsManager.GetString("MissingUpdater"));
Console.WriteLine(StringsManager.GetString("ContinuationPrompt"));
Console.ReadKey();
Expand Down
7 changes: 7 additions & 0 deletions Code/Melon/LocalClasses/StateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ public static void Init(IWebApi mWebApi, bool headless, bool conUI)
DisplayManager.MenuOptions.Add(StringsManager.GetString("ShortScanOption"), MelonScanner.MemoryScanShort);
DisplayManager.MenuOptions.Add(StringsManager.GetString("SettingsOption"), SettingsUI.Settings);
DisplayManager.MenuOptions.Add(StringsManager.GetString("ExitUIOption"), () => { Environment.Exit(0); });
DisplayManager.MenuOptions.Add(StringsManager.GetString("ExitMelonOption"), () =>
{
var file = File.Create($"{AppDomain.CurrentDomain.BaseDirectory}/GoAway.sdrq");
file.Write(new byte[] { 0x00 }, 0, 1);
file.Close();
Environment.Exit(0);
});

if (!headless)
{
Expand Down
3 changes: 2 additions & 1 deletion Code/MelonInstaller/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class Program
public static string installPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}/MelonInstall";
public static string versionToFind = "latest";
public static bool addAppIcons = false;
public static string Version = "1.1.4";
public static string Version = "1.1.5";
public static ResourceManager StringsManager { get; set; }

Check warning on line 16 in Code/MelonInstaller/Program.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

Non-nullable property 'StringsManager' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
[DllImport("libc")]
public static extern int system(string exec);
Expand Down Expand Up @@ -70,6 +70,7 @@ public static async Task<int> Main(string[] args)

if(LaunchArgs.ContainsKey("update"))
{
Thread.Sleep(1000);
await MelonInstallManager.Install(true);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion Code/MelonInstaller/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"MelonUpdater": {
"commandName": "Project",
"commandLineArgs": "-build -buildPath C:\\Users\\jhset\\Documents\\GitHub\\MelonMediaServer\\Code\\MelonWebApi"
"commandLineArgs": "-update -restart -installPath C:\\Users\\jhset\\Documents\\GitHub\\MelonMediaServer\\Code\\MelonWebApi\\bin\\Release\\net8.0 -lang EN"
}
}
}
36 changes: 28 additions & 8 deletions Code/MelonWebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public static class Program
public static WebApplication app;
public static MWebApi mWebApi;
public static FileSystemWatcher watcher;
public const string Version = "1.0.120.200";
public static FileSystemWatcher shutdownWatcher;
public const string Version = "1.0.110.200";

public static async Task<int> Main(string[] args)
{
Expand Down Expand Up @@ -90,19 +91,16 @@ public static async Task<int> Main(string[] args)
}
}

// Watch for settings changes
_ = Task.Run(() =>
{
// Watch for settings changes
watcher = new FileSystemWatcher();
watcher.Path = $"{StateManager.melonPath}/Configs/";
// Watch for changes in LastAccess and LastWrite times, and
// the renaming of files or directories.
watcher.NotifyFilter = NotifyFilters.LastWrite
| NotifyFilters.FileName
| NotifyFilters.DirectoryName;
// Only watch text files.
watcher.Filter = "*.json";
FileSystemEventHandler func = (sender, args) =>
Expand Down Expand Up @@ -133,10 +131,32 @@ public static async Task<int> Main(string[] args)
// Add event handlers.
watcher.Changed += func;
watcher.Created += func;
//watcher.Deleted += func;
// Begin watching.
watcher.EnableRaisingEvents = true;
// And again for so I can detect a shutdown rq
shutdownWatcher = new FileSystemWatcher();
shutdownWatcher.Path = $"{AppDomain.CurrentDomain.BaseDirectory}";
shutdownWatcher.NotifyFilter = NotifyFilters.LastWrite
| NotifyFilters.FileName
| NotifyFilters.DirectoryName;
shutdownWatcher.Filter = "*.sdrq";
FileSystemEventHandler updateFunc = (sender, args) =>
{
if (args.Name == "GoAway.sdrq")
{
StateManager.RestartServer = false;
app.StopAsync();
File.Delete($"{AppDomain.CurrentDomain.BaseDirectory}/GoAway.sdrq");
Environment.Exit(0);
}
};
shutdownWatcher.Changed += updateFunc;
shutdownWatcher.Created += updateFunc;
shutdownWatcher.EnableRaisingEvents = true;
});

var builder = WebApplication.CreateBuilder();
Expand Down

0 comments on commit 95a7a11

Please sign in to comment.