Skip to content

Commit

Permalink
Merge pull request #2 from sqparadox/master
Browse files Browse the repository at this point in the history
Steam Update
  • Loading branch information
rjtwins authored Jun 21, 2021
2 parents 76813f1 + a024a68 commit 76cdc52
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 7 deletions.
20 changes: 20 additions & 0 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 104 additions & 4 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private void Form1_Load(object sender, EventArgs e)
this.rotatingLabel1.NewText = "<- Low Priority --- High Priority ->"; // whatever you want to display
this.rotatingLabel1.ForeColor = Color.Black; // color to display
this.rotatingLabel1.RotateAngle = -90; // angle to rotate
this.button5.Enabled = false; //set Stop Search Button to disabled so the user won't be confused if a search isn't on-going
}

//Up button
Expand Down Expand Up @@ -124,6 +125,8 @@ private void SetVersionAndVender()
this.toolStripLabel1.Text = "Game Vendor : Epic Store";
this.selectToolStripMenuItem.Enabled = true;
this.searcgToolStripMenuItem.Enabled = true;
this.steamToolStripMenuItem.Enabled = true;
this.gogToolStripMenuItem.Enabled = true;
this.windowsStoreToolStripMenuItem.Enabled = true;
this.epicStoreToolStripMenuItem.Enabled = false;
this.button4.Enabled = true;
Expand All @@ -133,10 +136,34 @@ private void SetVersionAndVender()
this.toolStripLabel1.Text = "Game Vendor : Windows Store";
this.selectToolStripMenuItem.Enabled = false;
this.searcgToolStripMenuItem.Enabled = false;
this.steamToolStripMenuItem.Enabled = true;
this.gogToolStripMenuItem.Enabled = true;
this.windowsStoreToolStripMenuItem.Enabled = false;
this.epicStoreToolStripMenuItem.Enabled = true;
this.button4.Enabled = false;
}
else if (this.logic.Vendor == "STEAM")
{
this.toolStripLabel1.Text = "Game Vendor : Steam";
this.selectToolStripMenuItem.Enabled = true;
this.searcgToolStripMenuItem.Enabled = true;
this.steamToolStripMenuItem.Enabled = false;
this.gogToolStripMenuItem.Enabled = true;
this.windowsStoreToolStripMenuItem.Enabled = true;
this.epicStoreToolStripMenuItem.Enabled = true;
this.button4.Enabled = true;
}
else if (this.logic.Vendor == "GOG")
{
this.toolStripLabel1.Text = "Game Vendor : GOG";
this.selectToolStripMenuItem.Enabled = true;
this.searcgToolStripMenuItem.Enabled = true;
this.steamToolStripMenuItem.Enabled = true;
this.gogToolStripMenuItem.Enabled = false;
this.windowsStoreToolStripMenuItem.Enabled = true;
this.epicStoreToolStripMenuItem.Enabled = true;
this.button4.Enabled = true;
}
}
}

Expand Down Expand Up @@ -253,6 +280,7 @@ private void SelectInstallDirectory()
//Stop Search Button
private void button5_Click(object sender, EventArgs e)
{
this.button5.Enabled = false; //disable button since we are stopping the search
backgroundWorker1.CancelAsync();
}

Expand Down Expand Up @@ -317,6 +345,38 @@ private void importLoadOrderToolStripMenuItem_Click(object sender, EventArgs e)
this.LoadAndFill(true);
}

private void steamToolStripMenuItem_Click(object sender, EventArgs e)
{
ClearAll();
logic.WhipeInstallDirMemory();
this.logic.Vendor = "STEAM";
this.toolStripLabel1.Text = "Game Vendor : Steam";
this.selectToolStripMenuItem.Enabled = true;
this.searcgToolStripMenuItem.Enabled = true;
this.button4.Enabled = true;
this.steamToolStripMenuItem.Enabled = false;
this.windowsStoreToolStripMenuItem.Enabled = true;
this.epicStoreToolStripMenuItem.Enabled = true;
this.textBox1.Text = logic.BasePath;
LoadAndFill(false);
}
private void gogToolStripMenuItem_Click(object sender, EventArgs e)
{
ClearAll();
logic.WhipeInstallDirMemory();
this.logic.Vendor = "GOG";
this.toolStripLabel1.Text = "Game Vendor : GOG";
this.selectToolStripMenuItem.Enabled = true;
this.searcgToolStripMenuItem.Enabled = true;
this.button4.Enabled = true;
this.steamToolStripMenuItem.Enabled = true;
this.gogToolStripMenuItem.Enabled = false;
this.windowsStoreToolStripMenuItem.Enabled = true;
this.epicStoreToolStripMenuItem.Enabled = true;
this.textBox1.Text = logic.BasePath;
LoadAndFill(false);
}

private void windowsStoreToolStripMenuItem_Click(object sender, EventArgs e)
{
ClearAll();
Expand All @@ -327,6 +387,8 @@ private void windowsStoreToolStripMenuItem_Click(object sender, EventArgs e)
this.searcgToolStripMenuItem.Enabled = false;
this.button5.Enabled = false;
this.button4.Enabled = false;
this.steamToolStripMenuItem.Enabled = true;
this.gogToolStripMenuItem.Enabled = true;
this.windowsStoreToolStripMenuItem.Enabled = false;
this.epicStoreToolStripMenuItem.Enabled = true;

Expand All @@ -343,8 +405,9 @@ private void epicStoreToolStripMenuItem_Click(object sender, EventArgs e)
this.toolStripLabel1.Text = "Game Vendor : Epic Store";
this.selectToolStripMenuItem.Enabled = true;
this.searcgToolStripMenuItem.Enabled = true;
this.button5.Enabled = true;
this.button4.Enabled = true;
this.steamToolStripMenuItem.Enabled = true;
this.gogToolStripMenuItem.Enabled = true;
this.windowsStoreToolStripMenuItem.Enabled = true;
this.epicStoreToolStripMenuItem.Enabled = false;
this.textBox1.Text = logic.BasePath;
Expand All @@ -358,6 +421,7 @@ private void selectToolStripMenuItem_Click(object sender, EventArgs e)
private void searcgToolStripMenuItem_Click(object sender, EventArgs e)
{
ClearAll();
this.button5.Enabled = true; //enable the Stop Search button here so it's only enabled while we are searching
backgroundWorker1.RunWorkerAsync();
}

Expand All @@ -380,7 +444,7 @@ private void toolStripButton1_Click(object sender, EventArgs e)

private void button4_Click(object sender, EventArgs e)
{
if(this.logic.Vendor == "EPIC")
if (this.logic.Vendor == "EPIC")
{
try
{
Expand All @@ -390,12 +454,48 @@ private void button4_Click(object sender, EventArgs e)
{
Console.WriteLine(Ex.Message);
Console.WriteLine(Ex.StackTrace);
string message = "There was an error while trying to make EPIC Games Launcher laumch Mechwarrior 5.";
string message = "There was an error while trying to make EPIC Games Launcher launch Mechwarrior 5.";
string caption = "Error Launching";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);
}
}
else if (this.logic.Vendor == "STEAM")
{
try
{
System.Diagnostics.Process.Start(@"steam://rungameid/784080");
}
catch (Exception Ex)
{
Console.WriteLine(Ex.Message);
Console.WriteLine(Ex.StackTrace);
string message = "There was an error while trying to make Steam launch Mechwarrior 5.";
string caption = "Error Launching";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);
}
}
else if (this.logic.Vendor == "GOG")
{
string Gamepath = this.logic.BasePath;
Gamepath = Gamepath.Remove(Gamepath.Length - 13, 13);
Gamepath += "MechWarrior.exe";
try
{
Process.Start(Gamepath);
}
catch (Exception Ex)
{
Console.WriteLine(Ex.Message);
Console.WriteLine(Ex.StackTrace);
string message = "There was an error while trying to launch Mechwarrior 5.";
string caption = "Error Launching";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);
}
}else if (this.logic.Vendor == "WINDOWS")
}
else if (this.logic.Vendor == "WINDOWS")
{
//Dunno how this works at all..
string message = "This feature is not available in this version.";
Expand Down
76 changes: 73 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ public class MainLogic
public float Version = 0f;
public string Vendor = "";
public string BasePath = "";
public string WorkshopPath = "";
public ProgramData ProgramData = new ProgramData();

public JObject parent;
public string[] Directories;
public string[] WorkshopDirectories;

public Dictionary<string, ModObject> ModDetails = new Dictionary<string, ModObject>();
public Dictionary<string, bool> ModList = new Dictionary<string, bool>();
Expand Down Expand Up @@ -165,12 +167,35 @@ public void WhipeInstallDirMemory()
public void ParseDirectories()
{
this.Directories = Directory.GetDirectories(BasePath);
this.WorkshopDirectories = null; //instantiated as null for later checks
for (int i = 0; i < Directories.Length; i++)
{
string directory = this.Directories[i];
string[] temp = directory.Split('\\');
Directories[i] = temp[temp.Length - 1];
}
if (this.Vendor == "STEAM")
{
if (WorkshopPath == "")
{
Console.WriteLine("Found Steam version");
string workshopPath = BasePath;
workshopPath = workshopPath.Remove(workshopPath.Length - 46, 46);
Console.WriteLine($"trimmed path is {workshopPath}");
workshopPath += ("workshop\\content\\784080");
Console.WriteLine($"full workshop path is {workshopPath}");
WorkshopPath = workshopPath;
}
if (!Directory.Exists(WorkshopPath))
return;
this.WorkshopDirectories = Directory.GetDirectories(WorkshopPath);
for (int i = 0; i < WorkshopDirectories.Length; i++)
{
string directory = this.WorkshopDirectories[i];
string[] temp = directory.Split('\\');
WorkshopDirectories[i] = temp[temp.Length - 1];
}
}
}

public void SaveProgramData()
Expand Down Expand Up @@ -224,6 +249,7 @@ public void ClearAll()
this.ModList = new Dictionary<string, bool>();
this.ProgramData = new ProgramData();
this.BasePath = "";
this.WorkshopPath = "";
}

//Check if the mod dir is already present in data loaded from modlist.json, if not add it.
Expand All @@ -236,15 +262,24 @@ public void CombineDirModList()

ModList.Add(modDir, false);
}
if (this.Vendor == "STEAM" && this.WorkshopDirectories != null)
foreach (string modDir in this.WorkshopDirectories)
{
if (this.ModList.ContainsKey(modDir))
continue;

ModList.Add(modDir, false);
}

//Turns out there are sometimes "ghost" entries in the modlist.json for witch there are no directories left, lets remove those.
List<string> toRemove = new List<string>();
foreach (KeyValuePair<string, bool> entry in this.ModList)
{
if (this.Directories.Contains<string>(entry.Key))
{
continue;
}
else if (this.Vendor == "STEAM" && this.WorkshopDirectories != null)
if (this.WorkshopDirectories.Contains<string>(entry.Key))
continue;
toRemove.Add(entry.Key);
}
foreach (string key in toRemove)
Expand Down Expand Up @@ -286,15 +321,46 @@ public void LoadModDetails()
ModDetails.Remove(modDir);
}
}

}
if (this.Vendor == "STEAM" && this.WorkshopDirectories != null)
foreach (string modDir in this.WorkshopDirectories)
{
try
{
string modJson = File.ReadAllText(WorkshopPath + @"\" + modDir + @"\mod.json");
ModObject mod = JsonConvert.DeserializeObject<ModObject>(modJson);
this.ModDetails.Add(modDir, mod);
}
catch (Exception e)
{
string message = "ERROR loading mod.json in : " + modDir +
" folder will be skipped. " +
" If this is not a mod folder you can ignore ths message.";
string caption = "ERROR Loading";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);

if (ModList.ContainsKey(modDir))
{
ModList.Remove(modDir);
}
if (ModDetails.ContainsKey(modDir))
{
ModDetails.Remove(modDir);
}
}
}
}

public void SaveModDetails()
{
foreach (KeyValuePair<string, ModObject> entry in this.ModDetails)
{
string modJsonPath = BasePath + @"\" + entry.Key + @"\mod.json";
if (this.Vendor == "STEAM" && this.WorkshopDirectories != null)
if (this.WorkshopDirectories.Contains(entry.Key))
modJsonPath = WorkshopPath + @"\" + entry.Key + @"\mod.json";

JsonSerializer serializer = new JsonSerializer();
serializer.Formatting = Formatting.Indented;
using (StreamWriter sw = new StreamWriter(modJsonPath))
Expand Down Expand Up @@ -471,12 +537,16 @@ public class ModObject
{
public string displayName { set; get; }
public string version { set; get; }
public int buildNumber { set; get; }
public string description { set; get; }
public string author { set; get; }
public string authorURL { set; get; }
public float defaultLoadOrder { set; get; }
public string gameVersion { set; get; }
public List<string> manifest { get; set; }
public long steamPublishedFileId { set; get; }
public long steamLastSubmittedBuildNumber { set; get; }
public string steamModVisibility { set; get; }
}

public class ProgramData
Expand Down

0 comments on commit 76cdc52

Please sign in to comment.