Skip to content

Commit

Permalink
Implement exe commands: logs and reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sora-yx committed Apr 3, 2024
1 parent af2de1b commit 7bc52af
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
22 changes: 20 additions & 2 deletions SA-Mod-Manager/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public partial class App : Application
public static bool isFirstBoot = false; //used when installing the new manager manually
public static bool isLinux = false;
public static bool CancelUpdate = false;
public static bool isDebug = false;

public static string ManagerConfigFile = Path.Combine(ConfigFolder, "Manager.json");
public static ManagerSettings ManagerSettings { get; set; }
Expand Down Expand Up @@ -92,7 +93,7 @@ protected override async void OnStartup(StartupEventArgs e)

UpdateHelper.InitHttpClient();
Util.CheckLinux();
HandleVanillaTransition(args);
SetExeCommands(args);
Steam.Init();
SetupLanguages();
SetupThemes();
Expand Down Expand Up @@ -559,7 +560,7 @@ public static void CreateConfigFolder()
}
}

private static void HandleVanillaTransition(string[] args)
private static void SetExeCommands(string[] args)
{
foreach (var arg in args)
{
Expand All @@ -573,6 +574,23 @@ private static void HandleVanillaTransition(string[] args)
{
Util.DoVanillaFilesCleanup(args);
}
else if (arg == "debug")
{
App.isDebug = true;
Logger.Log("debug mode enabled");
}
else if (arg == "reset")
{
if (Directory.Exists(ConfigFolder))
{
try
{
Directory.Delete(ConfigFolder, true);
App.isFirstBoot = true;
}
catch { }
}
}
}
}

Expand Down
23 changes: 21 additions & 2 deletions SA-Mod-Manager/GamesInstall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -698,27 +698,33 @@ public static async Task<SetGame> SetGameInstall(string GamePath, Game game, boo

public static void AddGamesInstall()
{
Logger.Log("\nAuto Game Detection starts now...");
Logger.Log("Now looking for games in the same folder as the Manager...");
try
{
foreach (var game in GamesInstall.GetSupportedGames())
{
string path = Path.Combine(Environment.CurrentDirectory, game.exeName);

Logger.Log("Checking for: " + path);
if (File.Exists(path))
{
App.GamesList.Add(game);
AddMissingGamesList(game);
}
}

Logger.Log("Now looking for games through Steam...");

foreach (var game in GamesInstall.GetSupportedGames())
{
foreach (var pathValue in Steam.steamAppsPaths)
{
string gameInstallPath = Path.Combine(pathValue, "steamapps", "common", game.gameName);


Logger.Log("Checking for: " + gameInstallPath);
if (Directory.Exists(gameInstallPath) && !App.GamesList.Contains(game))
{
Logger.Log("Found Game!");
App.GamesList.Add(game);
AddMissingGamesList(game);
}
Expand Down Expand Up @@ -820,12 +826,16 @@ private static List<string> GetPathValues(string fileContent)
if (App.isLinux)
{
if (pathValue.Contains('\\'))
{
pathValue = pathValue.Replace('\\', '/');
Logger.Log("Linux: Detected backslashes, adjusted to forward slashes.");
}

Util.AdjustPathForLinux(ref pathValue);
}

paths.Add(Path.GetFullPath(pathValue)); //getfullpath fixes the extra backslashes, lol
Logger.Log("Path Found: " + Path.GetFullPath(pathValue));
}
}

Expand All @@ -837,10 +847,12 @@ private static void SetSteamAppsPaths()
if (SteamLocation is null)
return;

Logger.Log("Now looking for Steam config file...");
string configPath = Path.Combine(SteamLocation, "config", "libraryfolders.vdf");

if (File.Exists(configPath))
{
Logger.Log("libraryfolders.vdf file found... now attempting to get paths...");
steamAppsPaths = new();
string fileContent = File.ReadAllText(configPath);
steamAppsPaths = GetPathValues(fileContent);
Expand All @@ -854,6 +866,7 @@ private static void SetSteamPath()
string home = Environment.GetEnvironmentVariable("WINEHOMEDIR").Replace("\\??\\", "");
if (string.IsNullOrEmpty(home) == false)
{
Logger.Log("Steam Folder using Linux found at: " + home);
SteamLocation = Path.Combine(home, ".steam/steam");
return;
}
Expand All @@ -862,24 +875,30 @@ private static void SetSteamPath()
string steamDir = Environment.GetEnvironmentVariable("STEAM_DIR");
if (string.IsNullOrEmpty(steamDir) == false)
{
Logger.Log("Steam Folder using Linux found at: " + steamDir);
SteamLocation = steamDir;
return;
}
}
}


string steamInstallPath = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Valve\Steam", "InstallPath", null);

if (steamInstallPath == null)
{
var key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default).OpenSubKey("Software\\Valve\\Steam");

if (key != null && key.GetValue("SteamPath") is string steamPath)
{
SteamLocation = steamPath;
Logger.Log("Steam Folder was found through Windows method at: " + steamPath);
}
}
else
{
SteamLocation = steamInstallPath;
Logger.Log("Steam Folder was found through Windows method at: " + steamInstallPath);
}
}

Expand Down
30 changes: 30 additions & 0 deletions SA-Mod-Manager/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SAModManager
{
public static class Logger
{
private static readonly string logFilePath = "application.log";

public static void Log(string message)
{
if (App.isDebug == false)
return;

try
{
string logMessage = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {message}";
File.AppendAllText(logFilePath, logMessage + Environment.NewLine);
}
catch (Exception ex)
{
Console.WriteLine($"Error writing to log file: {ex.Message}");
}
}
}
}
5 changes: 5 additions & 0 deletions SA-Mod-Manager/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ public static void CheckLinux()
{
key.Close();
App.isLinux = true;
Logger.Log("Linux detected with first method");
return;
}

Expand All @@ -571,6 +572,7 @@ public static void CheckLinux()
if (!string.IsNullOrEmpty(winePrefix))
{
App.isLinux = true;
Logger.Log("Linux detected with second method");
return;
}

Expand All @@ -581,9 +583,12 @@ public static void CheckLinux()
if (File.Exists(path))
{
App.isLinux = true;
Logger.Log("Linux detected with last method, wow that was close.");
return;
}
}

Logger.Log("Linux wasn't detected, the Manager will act like we are on Windows.");
}

public static bool RunningAsAdmin()
Expand Down

0 comments on commit 7bc52af

Please sign in to comment.