Some Linux support, fix list color after update

This commit is contained in:
Norbi Peti 2020-07-03 02:00:08 +02:00
parent 407724fb0d
commit cbd6170757
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
5 changed files with 28 additions and 16 deletions

View file

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
@ -22,6 +22,7 @@
<ItemGroup> <ItemGroup>
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -16,21 +16,21 @@ namespace GCMM
public async Task InstallMod(ModInfo mod) public async Task InstallMod(ModInfo mod)
{ {
if (mod.DownloadURL == null) return; if (mod.DownloadURL == null) return;
if (!File.Exists(Settings.Default.GamePath + @"\Gamecraft.exe")) if (!File.Exists(GamePath(@"\Gamecraft.exe")))
{ {
MessageBox.Show("Gamecraft not found. Set the correct path in Settings."); MessageBox.Show("Gamecraft not found. Set the correct path in Settings.");
return; return;
} }
var tmp = Directory.CreateDirectory("temp"); var tmp = Directory.CreateDirectory("temp");
var plugins = Directory.CreateDirectory(Settings.Default.GamePath + @"\Plugins"); var plugins = Directory.CreateDirectory(GamePath(@"\Plugins"));
string tmppath = tmp.FullName + "\\" + mod.Name; string tmppath = tmp.FullName + Path.DirectorySeparatorChar + mod.Name;
using (var client = GetClient()) using (var client = GetClient())
{ {
await client.DownloadFileTaskAsync(mod.DownloadURL, tmppath); await client.DownloadFileTaskAsync(mod.DownloadURL, tmppath);
string disposition = client.ResponseHeaders["Content-Disposition"]; string disposition = client.ResponseHeaders["Content-Disposition"];
string filename = disposition.Substring(disposition.IndexOf("filename=") + 10).Replace("\"", ""); string filename = disposition.Substring(disposition.IndexOf("filename=") + 10).Replace("\"", "");
if (filename.EndsWith(".dll")) if (filename.EndsWith(".dll"))
File.Move(tmppath, plugins.FullName + "\\" + mod.Name + ".dll"); //Force mod name to make uninstalls & identifying easier File.Move(tmppath, plugins.FullName + Path.DirectorySeparatorChar + mod.Name + ".dll"); //Force mod name to make uninstalls & identifying easier
else if (filename.EndsWith(".zip")) else if (filename.EndsWith(".zip"))
{ {
bool pluginOnly = true; bool pluginOnly = true;
@ -120,7 +120,7 @@ namespace GCMM
{ {
LoadFileList(mod); LoadFileList(mod);
if (mod.ModFiles.Count == 0) //A single DLL if (mod.ModFiles.Count == 0) //A single DLL
File.Delete(Settings.Default.GamePath + @"\Plugins\" + mod.Name + ".dll"); File.Delete(GamePath(@"\Plugins\" + mod.Name + ".dll"));
else //A ZIP else //A ZIP
{ {
foreach (string file in mod.ModFiles) foreach (string file in mod.ModFiles)

View file

@ -19,7 +19,7 @@ namespace GCMM
public void GetInstalledMods() public void GetInstalledMods()
{ {
foreach (var modPath in Directory.GetFiles(Settings.Default.GamePath + @"\Plugins", "*.dll")) foreach (var modPath in Directory.GetFiles(GamePath(@"\Plugins"), "*.dll"))
{ {
try try
{ {
@ -122,6 +122,8 @@ namespace GCMM
} }
if (mod.LatestVersion != null && mod.Version != null && mod.Version < mod.LatestVersion) if (mod.LatestVersion != null && mod.Version != null && mod.Version < mod.LatestVersion)
item.ForeColor = Color.Blue; item.ForeColor = Color.Blue;
else
item.ForeColor = modlist.ForeColor;
} }
public void RemoveModFromList(ModInfo mod) public void RemoveModFromList(ModInfo mod)

View file

@ -17,24 +17,25 @@ namespace GCMM
{ {
public bool? CheckIfPatched() public bool? CheckIfPatched()
{ {
if (!File.Exists(Settings.Default.GamePath + @"\IPA.exe")) if (!File.Exists(GamePath(@"\IPA.exe")))
{ {
status.Text = "Status: Patcher missing\nClicking Play will install it"; status.Text = "Status: Patcher missing\nClicking Play will install it";
return null; return null;
} }
string nopatch = "Status: Unpatched" + (unpatched.Checked ? "" : "\nClicking Play patches it"); string nopatch = "Status: Unpatched" + (unpatched.Checked ? "" : "\nClicking Play patches it");
if (!Directory.Exists(Settings.Default.GamePath + @"\IPA\Backups\Gamecraft")) string backups = GamePath(@"\IPA\Backups\Gamecraft");
if (!Directory.Exists(backups))
{ {
status.Text = nopatch; status.Text = nopatch;
return false; return false;
} }
string backup = Directory.EnumerateDirectories(Settings.Default.GamePath + @"\IPA\Backups\Gamecraft").OrderByDescending(s => s).FirstOrDefault(); string backup = Directory.EnumerateDirectories(backups).OrderByDescending(s => s).FirstOrDefault();
if (backup == null) if (backup == null)
{ {
status.Text = nopatch; status.Text = nopatch;
return false; return false;
} }
if (File.GetLastWriteTime(Settings.Default.GamePath + @"\Gamecraft_Data\Managed\Assembly-CSharp.dll") if (File.GetLastWriteTime(GamePath(@"\Gamecraft_Data\Managed\Assembly-CSharp.dll"))
> //If the file was updated at least 2 minutes after patching > //If the file was updated at least 2 minutes after patching
Directory.GetLastWriteTime(backup).AddMinutes(2)) Directory.GetLastWriteTime(backup).AddMinutes(2))
{ {
@ -75,8 +76,8 @@ namespace GCMM
return; return;
} }
if (!status.Value ^ unpatched.Checked) if (!status.Value ^ unpatched.Checked)
{ { //TODO: Wine
var psi = new ProcessStartInfo(Settings.Default.GamePath + @"\IPA.exe", "Gamecraft.exe " var psi = new ProcessStartInfo(GamePath(@"\IPA.exe"), "Gamecraft.exe "
+ (unpatched.Checked ? "--revert " : "") + "--nowait") + (unpatched.Checked ? "--revert " : "") + "--nowait")
{ {
UseShellExecute = false, UseShellExecute = false,

View file

@ -32,7 +32,7 @@ namespace GCMM
} }
public string GetGameFolder() public string GetGameFolder()
{ { //TODO
string libs; string libs;
if (Environment.OSVersion.Platform == PlatformID.Win32NT) if (Environment.OSVersion.Platform == PlatformID.Win32NT)
libs = @"C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf"; libs = @"C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf";
@ -59,7 +59,7 @@ namespace GCMM
var ofd = new OpenFileDialog(); var ofd = new OpenFileDialog();
ofd.Filter = "Gamecraft executable|Gamecraft.exe"; ofd.Filter = "Gamecraft executable|Gamecraft.exe";
ofd.Title = "Game location"; ofd.Title = "Game location";
ofd.InitialDirectory = @"C:\Program Files (x86)\Steam\steamapps\common\"; ofd.InitialDirectory = @"C:\Program Files (x86)\Steam\steamapps\common\"; //TODO
ofd.CheckFileExists = true; ofd.CheckFileExists = true;
ofd.ShowDialog(); ofd.ShowDialog();
if (string.IsNullOrWhiteSpace(ofd.FileName)) if (string.IsNullOrWhiteSpace(ofd.FileName))
@ -77,7 +77,10 @@ namespace GCMM
return; return;
} }
if ((CheckIfPatched() ?? false) || unpatched.Checked) if ((CheckIfPatched() ?? false) || unpatched.Checked)
Process.Start("steam://run/1078000/"); if (Environment.OSVersion.Platform == PlatformID.Win32NT)
Process.Start("steam://run/1078000/");
else
Process.Start("xdg-open", "steam://run/1078000/");
}; };
if (InvokeRequired) if (InvokeRequired)
Invoke(act); Invoke(act);
@ -121,5 +124,10 @@ namespace GCMM
if (desc) if (desc)
modlist_SelectedIndexChanged(modlist, null); modlist_SelectedIndexChanged(modlist, null);
} }
public string GamePath(string path)
{
return (Settings.Default.GamePath + path).Replace('\\', Path.DirectorySeparatorChar);
}
} }
} }