diff --git a/Form1.Designer.cs b/Form1.Designer.cs index dc3c6b9..72d21ef 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -45,6 +45,8 @@ private void InitializeComponent() this.searcgToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.changeVendorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.windowsStoreToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.steamToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.gogToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.epicStoreToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.exportLoadOrderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -195,12 +197,28 @@ private void InitializeComponent() // changeVendorToolStripMenuItem // this.changeVendorToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.steamToolStripMenuItem, + this.gogToolStripMenuItem, this.windowsStoreToolStripMenuItem, this.epicStoreToolStripMenuItem}); this.changeVendorToolStripMenuItem.Name = "changeVendorToolStripMenuItem"; this.changeVendorToolStripMenuItem.Size = new System.Drawing.Size(172, 22); this.changeVendorToolStripMenuItem.Text = "Set Vendor"; // + // steamToolStripMenuItem + // + this.steamToolStripMenuItem.Name = "steamToolStripMenuItem"; + this.steamToolStripMenuItem.Size = new System.Drawing.Size(153, 22); + this.steamToolStripMenuItem.Text = "Steam"; + this.steamToolStripMenuItem.Click += new System.EventHandler(this.steamToolStripMenuItem_Click); + // + // gogToolStripMenuItem + // + this.gogToolStripMenuItem.Name = "gogToolStripMenuItem"; + this.gogToolStripMenuItem.Size = new System.Drawing.Size(153, 22); + this.gogToolStripMenuItem.Text = "GOG"; + this.gogToolStripMenuItem.Click += new System.EventHandler(this.gogToolStripMenuItem_Click); + // // windowsStoreToolStripMenuItem // this.windowsStoreToolStripMenuItem.Name = "windowsStoreToolStripMenuItem"; @@ -400,6 +418,8 @@ private void InitializeComponent() private System.Windows.Forms.ColumnHeader version; private System.Windows.Forms.ToolStripMenuItem changeVendorToolStripMenuItem; public System.Windows.Forms.ToolStripLabel toolStripLabel1; + private System.Windows.Forms.ToolStripMenuItem steamToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem gogToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem windowsStoreToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem epicStoreToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem installDirectoryToolStripMenuItem; diff --git a/Form1.cs b/Form1.cs index c93707d..aa5264f 100644 --- a/Form1.cs +++ b/Form1.cs @@ -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 @@ -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; @@ -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; + } } } @@ -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(); } @@ -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(); @@ -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; @@ -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; @@ -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(); } @@ -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 { @@ -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."; diff --git a/Program.cs b/Program.cs index ecdd641..6d4aca4 100644 --- a/Program.cs +++ b/Program.cs @@ -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 ModDetails = new Dictionary(); public Dictionary ModList = new Dictionary(); @@ -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() @@ -224,6 +249,7 @@ public void ClearAll() this.ModList = new Dictionary(); 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. @@ -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 toRemove = new List(); foreach (KeyValuePair entry in this.ModList) { if (this.Directories.Contains(entry.Key)) - { continue; - } + else if (this.Vendor == "STEAM" && this.WorkshopDirectories != null) + if (this.WorkshopDirectories.Contains(entry.Key)) + continue; toRemove.Add(entry.Key); } foreach (string key in toRemove) @@ -286,8 +321,35 @@ 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(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() @@ -295,6 +357,10 @@ public void SaveModDetails() foreach (KeyValuePair 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)) @@ -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 manifest { get; set; } + public long steamPublishedFileId { set; get; } + public long steamLastSubmittedBuildNumber { set; get; } + public string steamModVisibility { set; get; } } public class ProgramData