diff --git a/Logic.cs b/Logic.cs new file mode 100644 index 0000000..5965190 --- /dev/null +++ b/Logic.cs @@ -0,0 +1,155 @@ +using Newtonsoft.Json; +using Octokit; +using System; +using System.IO; +using System.Net; + +namespace MW5LOMLauncherV2 +{ + public class Logic + { + public static Logic logic; + ProgramData ProgramData = new ProgramData(); + string ProgramDataPath = ""; + string LatestVersion = ""; + public bool ExeExists = false; + bool GithubUnreachable = false; + + public Logic(OutputForm form1) + { + Logic.logic = this; + this.ProgramDataPath = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + + @"\MW5LoadOrderManager"; + + bool update = false; + + try + { + var client = new GitHubClient(new ProductHeaderValue("MW5LoadOrderManagerUpdater")); + this.LatestVersion = client.Repository.Release.GetLatest("rjtwins", "MW5-Mod-Manager").Result.TagName; + } + catch (Exception e) + { + form1.listBox1.Items.Add("Github unreachable for update trying to launch from existing executable..."); + Console.WriteLine("Github unreachable for update trying to launch from existing executable..."); + GithubUnreachable = true; + + Console.WriteLine(e.Message); + Console.WriteLine(e.StackTrace); + } + + //Is this our first time running? + if (LoadGenProgramData()) + { + form1.listBox1.Items.Add("First time startup or corrupted files detected, staring update/restore..."); + Console.WriteLine("First time startup or corrupted files detected, staring update/restore..."); + + //we are running a "fresh" version with no stored program data or a corrupt program data file. + update = true; + } + else if(!GithubUnreachable) + { + form1.listBox1.Items.Add("Checking for updates..."); + form1.listBox1.Items.Add(String.Format("The latest release is tagged at {0} we are running {1}", + LatestVersion, + this.ProgramData.version)); + + Console.WriteLine("Checking for updates..."); + Console.WriteLine( + "The latest release is tagged at {0} we are running {1}", + LatestVersion, + this.ProgramData.version); + + if (this.ProgramData.version < float.Parse(LatestVersion)) + { + form1.listBox1.Items.Add("A new version is available, starting update..."); + Console.WriteLine("A new version is available, starting update..."); + update = true; + } + } + + if (update && !GithubUnreachable) + { + try + { + using (var webClient = new WebClient()) + { + string url = String.Format("https://github.com/rjtwins/MW5-Mod-Manager/releases/download/{0}/MW5.Mod.Manager.exe", this.LatestVersion); + webClient.DownloadFile(url, this.ProgramDataPath + @"\MW5 Mod Manager.exe"); + } + this.ProgramData.version = float.Parse(this.LatestVersion); + + //Update program data + JsonSerializer serializer = new JsonSerializer(); + serializer.Formatting = Formatting.Indented; + using (StreamWriter sw = new StreamWriter(ProgramDataPath + @"\ProgramData.json")) + using (JsonWriter writer = new JsonTextWriter(sw)) + { + serializer.Serialize(writer, this.ProgramData); + } + } + catch (Exception e) + { + Console.WriteLine(e.Message); + Console.WriteLine(e.StackTrace); + } + } + form1.listBox1.Items.Add("Done, starting MW5 Load Order Manager"); + Console.WriteLine("Done, starting MW5 Mod Loader Manager"); + + form1.timer1.Enabled = true; + form1.timer1.Start(); + } + + internal static void StartMainProgram() + { + //Start the main program + System.Diagnostics.Process.Start(Logic.logic.ProgramDataPath + @"\MW5 Mod Manager.exe"); + } + + public bool LoadGenProgramData() + { + //Load install dir from previous session: + if (!File.Exists(ProgramDataPath + @"\ProgramData.json")) + { + System.IO.Directory.CreateDirectory(ProgramDataPath); + System.IO.File.Create(ProgramDataPath + @"\ProgramData.json").Close(); + this.ProgramData.vendor = "EPIC"; + this.ProgramData.installdir = new string[2] {"",""}; + this.ProgramData.version = 0f; + Console.WriteLine(ProgramDataPath + @"\ProgramData.json was not found."); + return true; + } + try + { + string json = File.ReadAllText(ProgramDataPath + @"\ProgramData.json"); + this.ProgramData = JsonConvert.DeserializeObject(json); + } + catch (Exception e) + { + Console.WriteLine(ProgramDataPath + @"\ProgramData.json unreadable."); + //Console.WriteLine(e.Message); + //Console.WriteLine(e.StackTrace); + return true; + } + if (this.ProgramData.version <= 0f) + { + Console.WriteLine("Version outside of possible range."); + return true; + } + + + if (File.Exists(ProgramDataPath + @"\MW5 Mod Manager.exe")) + { + ExeExists = true; + } + //ProgramData.json is fine but the exe file is missing? Update to get it. + else + { + Console.WriteLine(ProgramDataPath + @"\MW5 Mod Manager.exe not found."); + return true; + } + return false; + } + } +} diff --git a/MW5LOMLauncherV2.csproj b/MW5LOMLauncherV2.csproj index b960365..fa5fd0a 100644 --- a/MW5LOMLauncherV2.csproj +++ b/MW5LOMLauncherV2.csproj @@ -12,6 +12,7 @@ 512 true true + false publish\ true Disk @@ -22,10 +23,11 @@ false false true - 0 + true + 1 1.0.0.%2a - false false + true true @@ -43,13 +45,46 @@ pdbonly true bin\Release\ - TRACE + DEBUG;TRACE prompt 4 + MinimumRecommendedRules.ruleset + false + true + true + false exeIcon.ico + + EA77E3833AE0941F5D372A3C9F6384745177644B + + + + + + + false + + + false + + + false + + + MW5LauncherKey.pfx + + + false + + + Properties\app.manifest + + + Internet + @@ -64,16 +99,18 @@ - + + Form - - Form1.cs + + OutputForm.cs + - - Form1.cs + + OutputForm.cs ResXFileCodeGenerator @@ -85,6 +122,10 @@ Resources.resx True + + + + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/Form1.Designer.cs b/OutputForm.Designer.cs similarity index 94% rename from Form1.Designer.cs rename to OutputForm.Designer.cs index 68a89bb..b91e028 100644 --- a/Form1.Designer.cs +++ b/OutputForm.Designer.cs @@ -1,6 +1,6 @@ namespace MW5LOMLauncherV2 { - partial class Form1 + partial class OutputForm { /// /// Required designer variable. @@ -40,6 +40,7 @@ private void InitializeComponent() this.listBox1.Name = "listBox1"; this.listBox1.Size = new System.Drawing.Size(513, 251); this.listBox1.TabIndex = 0; + this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged); // // timer1 // diff --git a/Form1.cs b/OutputForm.cs similarity index 86% rename from Form1.cs rename to OutputForm.cs index 90ebaa9..2604122 100644 --- a/Form1.cs +++ b/OutputForm.cs @@ -11,10 +11,10 @@ namespace MW5LOMLauncherV2 { - public partial class Form1 : Form + public partial class OutputForm : Form { - Logic logic; - public Form1() + private Logic logic; + public OutputForm() { InitializeComponent(); this.logic = new Logic(this); @@ -45,5 +45,10 @@ public void timer1_Tick(object sender, EventArgs e) } Environment.Exit(0); } + + private void listBox1_SelectedIndexChanged(object sender, EventArgs e) + { + + } } } diff --git a/Form1.resx b/OutputForm.resx similarity index 100% rename from Form1.resx rename to OutputForm.resx diff --git a/Program.cs b/Program.cs index d7e34e2..c29f80f 100644 --- a/Program.cs +++ b/Program.cs @@ -1,10 +1,6 @@ -using Newtonsoft.Json; -using Octokit; -using System; +using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Net; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -14,7 +10,7 @@ namespace MW5LOMLauncherV2 { static class Program { - public static Form1 Form1; + public static OutputForm Form1; /// /// The main entry point for the application. /// @@ -23,162 +19,8 @@ static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Program.Form1 = new Form1(); + Program.Form1 = new OutputForm(); Application.Run(Program.Form1); } } - - public class Logic - { - public static Logic logic; - ProgramData ProgramData = new ProgramData(); - string ProgramDataPath = ""; - string LatestVersion = ""; - public bool ExeExists = false; - bool GithubUnreachable = false; - - public Logic(Form1 form1) - { - Logic.logic = this; - this.ProgramDataPath = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + - @"\MW5LoadOrderManager"; - - bool update = false; - - try - { - var client = new GitHubClient(new ProductHeaderValue("MW5LoadOrderManagerUpdater")); - this.LatestVersion = client.Repository.Release.GetLatest("rjtwins", "MW5-Mod-Manager").Result.TagName; - } - catch (Exception e) - { - form1.listBox1.Items.Add("Github unreachable for update trying to launch from existing executable..."); - Console.WriteLine("Github unreachable for update trying to launch from existing executable..."); - GithubUnreachable = true; - - Console.WriteLine(e.Message); - Console.WriteLine(e.StackTrace); - } - - //Is this our first time running? - if (LoadGenProgramData()) - { - form1.listBox1.Items.Add("First time startup or corrupted files detected, staring update/restore..."); - Console.WriteLine("First time startup or corrupted files detected, staring update/restore..."); - - //we are running a "fresh" version with no stored program data or a corrupt program data file. - update = true; - } - else if(!GithubUnreachable) - { - form1.listBox1.Items.Add("Checking for updates..."); - form1.listBox1.Items.Add(String.Format("The latest release is tagged at {0} we are running {1}", - LatestVersion, - this.ProgramData.version)); - - Console.WriteLine("Checking for updates..."); - Console.WriteLine( - "The latest release is tagged at {0} we are running {1}", - LatestVersion, - this.ProgramData.version); - - if (this.ProgramData.version < float.Parse(LatestVersion)) - { - form1.listBox1.Items.Add("A new version is available, starting update..."); - Console.WriteLine("A new version is available, starting update..."); - update = true; - } - } - - if (update && !GithubUnreachable) - { - try - { - using (var webClient = new WebClient()) - { - string url = String.Format("https://github.com/rjtwins/MW5-Mod-Manager/releases/download/{0}/MW5.Mod.Manager.exe", this.LatestVersion); - webClient.DownloadFile(url, this.ProgramDataPath + @"\MW5 Mod Manager.exe"); - } - this.ProgramData.version = float.Parse(this.LatestVersion); - - //Update program data - JsonSerializer serializer = new JsonSerializer(); - serializer.Formatting = Formatting.Indented; - using (StreamWriter sw = new StreamWriter(ProgramDataPath + @"\ProgramData.json")) - using (JsonWriter writer = new JsonTextWriter(sw)) - { - serializer.Serialize(writer, this.ProgramData); - } - } - catch (Exception e) - { - Console.WriteLine(e.Message); - Console.WriteLine(e.StackTrace); - } - } - form1.listBox1.Items.Add("Done, starting MW5 Load Order Manager"); - Console.WriteLine("Done, starting MW5 Mod Loader Manager"); - - form1.timer1.Enabled = true; - form1.timer1.Start(); - } - - internal static void StartMainProgram() - { - //Start the main program - System.Diagnostics.Process.Start(Logic.logic.ProgramDataPath + @"\MW5 Mod Manager.exe"); - } - - public bool LoadGenProgramData() - { - //Load install dir from previous session: - if (!File.Exists(ProgramDataPath + @"\ProgramData.json")) - { - System.IO.Directory.CreateDirectory(ProgramDataPath); - System.IO.File.Create(ProgramDataPath + @"\ProgramData.json").Close(); - this.ProgramData.vendor = "EPIC"; - this.ProgramData.installdir = ""; - this.ProgramData.version = 0f; - Console.WriteLine(ProgramDataPath + @"\ProgramData.json was not found."); - return true; - } - try - { - string json = File.ReadAllText(ProgramDataPath + @"\ProgramData.json"); - this.ProgramData = JsonConvert.DeserializeObject(json); - } - catch (Exception e) - { - Console.WriteLine(ProgramDataPath + @"\ProgramData.json unreadable."); - //Console.WriteLine(e.Message); - //Console.WriteLine(e.StackTrace); - return true; - } - if (this.ProgramData.version <= 0f) - { - Console.WriteLine("Version outside of possible range."); - return true; - } - - - if (File.Exists(ProgramDataPath + @"\MW5 Mod Manager.exe")) - { - ExeExists = true; - } - //ProgramData.json is fine but the exe file is missing? Update to get it. - else - { - Console.WriteLine(ProgramDataPath + @"\MW5 Mod Manager.exe not found."); - return true; - } - return false; - } - } - - public class ProgramData - { - public string vendor { set; get; } - public float version { set; get; } - public string installdir { set; get; } - } } diff --git a/ProgramData.cs b/ProgramData.cs new file mode 100644 index 0000000..0fac4da --- /dev/null +++ b/ProgramData.cs @@ -0,0 +1,9 @@ +namespace MW5LOMLauncherV2 +{ + public class ProgramData + { + public string vendor { set; get; } + public float version { set; get; } + public string[] installdir { set; get; } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 96d2452..b385271 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -17,7 +17,7 @@ // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] +[assembly: ComVisible(true)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("2c92e0c2-5bfc-46d9-8d0d-40fd312607ae")] @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0.0")] -[assembly: AssemblyFileVersion("2.0.0.0")] +[assembly: AssemblyVersion("2.1.0.0")] +[assembly: AssemblyFileVersion("2.1.0.0")] diff --git a/Properties/app.manifest b/Properties/app.manifest new file mode 100644 index 0000000..ef267b2 --- /dev/null +++ b/Properties/app.manifest @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file