private void Form_Load(object sender, EventArgs e) { MyToolkit.ActivityLog("Loading application."); try { // Attempt to kill any other version of the patcher // // that may be running // ProcessKiller(); this.Text += " " + Application.ProductVersion; Skin(); ScanParameters(); LoadManifestList(); timer1.Enabled = Setup(); } catch (Exception ex) { MyToolkit.ErrorReporter(ex, this.Name + ".Form_Load"); } loaded = true; MyToolkit.ActivityLog("Load application complete."); }
private long DirectoryCount(string sourceDirName) { long count = 0; try { DirectoryInfo dir = new DirectoryInfo(sourceDirName); DirectoryInfo[] dirs = dir.GetDirectories(); FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { if (Kill) { return(0); } try { count += file.Length; } catch (Exception) { } } foreach (DirectoryInfo subdir in dirs) { count += DirectoryCount(subdir.FullName); } } catch (Exception ex) { MyToolkit.ErrorReporter(ex, "DirCopy.DirectoryCopyStep"); } return(count); }
public static void SelfRelocate() { try { if (Application.StartupPath == Settings.GamePath) { return; } if (!File.Exists(Application.ExecutablePath)) { return; } string ShortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); string ShortcutTarget = Path.Combine(Settings.GamePath, "CreamSoda.exe"); MyToolkit.ActivityLog("Self Relocating CreamSoda to \"" + ShortcutTarget + "\""); if (!Directory.Exists(Settings.GamePath)) { Directory.CreateDirectory(Settings.GamePath); } try { if (File.Exists(ShortcutTarget)) { File.Delete(ShortcutTarget); } File.Move(Application.ExecutablePath, ShortcutTarget); } catch (Exception) { File.Copy(Application.ExecutablePath, ShortcutTarget); try { File.Move(Application.ExecutablePath, Path.Combine(Application.StartupPath, "deleteme.txt")); } catch (Exception) { MyToolkit.ActivityLog("Failed to relocate CreamSoda to \"" + ShortcutTarget + "\""); } } try { using (ShellLink shortcut = new ShellLink()) { shortcut.Target = ShortcutTarget; //shortcut.WorkingDirectory = Path.GetDirectoryName(ShortcutTarget); shortcut.Description = "Drink up!"; shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal; shortcut.Save(Path.Combine(ShortcutPath, "CreamSoda.lnk")); } } catch (Exception ex) { MyToolkit.ActivityLog("Failed to create desktop shortcut \"" + ShortcutTarget + "\""); MessageBox.Show(ex.Message); } } catch (Exception ex) { MyToolkit.ErrorReporter(ex, "Preferences.SelfRelocate"); } }
private void DirectoryCopyStep(string sourceDirName, string destDirName, bool copySubDirs = true, bool replace = true) { try{ DirectoryInfo dir = new DirectoryInfo(sourceDirName); DirectoryInfo[] dirs = dir.GetDirectories(); if (!dir.Exists) { throw new DirectoryNotFoundException( "Source directory does not exist or could not be found: " + sourceDirName); } if (!Directory.Exists(destDirName)) { Directory.CreateDirectory(destDirName); } FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { if (Kill) { return; } string temppath = Path.Combine(destDirName, file.Name); if (File.Exists(temppath) && replace) { File.SetAttributes(temppath, File.GetAttributes(temppath) & ~FileAttributes.ReadOnly); File.Delete(temppath); } try { file.CopyTo(temppath, true); } catch (Exception) { } m_FilesDone += file.Length; } if (copySubDirs) { foreach (DirectoryInfo subdir in dirs) { string temppath = Path.Combine(destDirName, subdir.Name); DirectoryCopyStep(subdir.FullName, temppath, copySubDirs); } } } catch (Exception ex) { MyToolkit.ErrorReporter(ex, "DirCopy.DirectoryCopyStep"); } }
private void btnScreenshots_Click(object sender, EventArgs e) { try { MyToolkit.ActivityLog("User clicked to open screenshots directory"); string screenshotDir = Path.Combine(Settings.GamePath, "screenshots"); if (!Directory.Exists(screenshotDir)) { Directory.CreateDirectory(screenshotDir); } System.Diagnostics.Process.Start("explorer.exe", screenshotDir); } catch (Exception ex) { MyToolkit.ErrorReporter(ex, this.Name + ".btScreenshots_Click"); } }
public Fingerprint(string RootPath, string FileName, string Checksum) { try{ m_RootPath = RootPath; m_FileName = FileName.Replace(".EXE", ".exe"); // Load size from the file info m_Size = (new FileInfo(FileName)).Length; // Make sure the checksum is lowercase m_Checksum = Checksum.ToLower(); } catch (Exception ex) { MyToolkit.ErrorReporter(ex, "Fingerprint.Constructor2"); } }
private void ReValidate() { try { pnlErrors.Visible = false; webBrowser1.Visible = true; MyToolkit.ActivityLog("Revalidation process started"); ListBox1.DataSource = null; File.Delete(Path.Combine(Settings.GamePath, "Bourbonlog.xml")); timer1.Enabled = Setup(); StartUp(); } catch (Exception ex) { MyToolkit.ErrorReporter(ex, this.Name + ".Form_Load"); } }
public Fingerprint(string RootPath, string FileName, string Checksum, long Size) { try { m_RootPath = RootPath; m_FileName = FileName.Replace(".EXE", ".exe"); // Make sure the checksum is lowercase m_Checksum = Checksum.ToLower(); // ... yea... overcommenting! m_Size = Size; } catch (Exception ex) { MyToolkit.ErrorReporter(ex, "Fingerprint.Constructor2"); } }
/**********************************************************************/ public Fingerprint(string RootPath, string FileName) { try { m_RootPath = RootPath; m_FileName = FileName.Replace(".EXE", ".exe"); if (File.Exists(FullName)) { m_Size = (new FileInfo(FullName)).Length; } else { m_Size = 0; } m_Checksum = GenerateHash(); } catch (Exception ex) { MyToolkit.ErrorReporter(ex, "Fingerprint.Constructor1"); } }
private void FlagVerified(string file, long size, string md5) { try { FileInfo fi = new FileInfo(Path.Combine(Settings.GamePath, file)); XElement e = new XElement("file"); e.Add(new XAttribute("name", file)); e.Add(new XAttribute("size", size)); e.Add(new XAttribute("md5", md5)); e.Add(new XAttribute("ModDate", fi.LastWriteTime.ToString(fi.LastWriteTime.ToString("yyyy.MM.dd.HH.mm.ss")))); LogNew.Add(e); // Sometimes we may run this through too fast and the file may be locked // we will retry a save attempt for up to 3 seconds, if we are not able // to save without errors by then we do one final save attempt and // report error. bool saveSuccessful = false; Stopwatch sw = new Stopwatch(); sw.Start(); while (sw.ElapsedMilliseconds < 3000 && !saveSuccessful) { try { LogNew.Save(LogPath); saveSuccessful = true; } catch (Exception) { saveSuccessful = false; } } // OK, if we did not save, here is our last attempt! if (!saveSuccessful) { LogNew.Save(LogPath); } } catch (Exception ex) { MyToolkit.ErrorReporter(ex, "WorkThread.FlagVerified"); } }
private void btnPlay_Click(object sender, EventArgs e) { try { MyToolkit.ActivityLog("User clicked play with the following profile: " + ((LaunchProfile)ListBox1.SelectedItem).Text); var startInfo = new ProcessStartInfo(); startInfo.WorkingDirectory = Settings.GamePath; startInfo.FileName = ((LaunchProfile)ListBox1.SelectedItem).Exec; startInfo.Arguments = ((LaunchProfile)ListBox1.SelectedItem).Params; startInfo.Arguments += " " + Settings.GameParams; Process.Start(startInfo); if (Settings.QuitOnLaunch) { Application.Exit(); } } catch (Exception ex) { MyToolkit.ErrorReporter(ex, this.Name + ".btnPlay_Click"); } }
private void StartUp() { try { MyToolkit.ActivityLog("Started patching"); string PathRoot = Settings.GamePath; string LocalManifest = PathRoot + @"Bourbon.xml"; btnPlay.Text = "..."; btnPlay.Enabled = false; cbManifest.Enabled = false; myWorker = new WorkThread(ManifestURL); myWorker.LocalManifest = LocalManifest; myWorker.PathRoot = PathRoot; myWorker.DownloadManifest(); } catch (Exception ex) { MyToolkit.ErrorReporter(ex, this.Name + ".StartUp"); } }
private bool Setup() { try { if (Settings.SetupNeeded) { MyToolkit.ActivityLog("Setting up CreamSoda"); string myPath = ""; bool PathValid = false; FolderBrowserDialog FileBox; do { FileBox = new FolderBrowserDialog { Description = "Select a location where you would like to install CreamSoda; preferably under My Documents or Application Data. Do not use a folder under Program Files.", SelectedPath = Application.StartupPath }; if (FileBox.ShowDialog(this) == System.Windows.Forms.DialogResult.Cancel) { MessageBox.Show("You must select a valid install directory to continue.\nCreamSoda will now quit. Restart CreamSoda once you have a valid installation path."); Application.Exit(); return(false); } myPath = FileBox.SelectedPath; PathValid = true; } while (!PathValid); Settings.GamePath = myPath; MyToolkit.ActivityLog("CreamSoda installed at \"" + myPath + "\""); } SelfRelocate(); return(true); } catch (Exception ex) { MyToolkit.ErrorReporter(ex, this.Name + ".Setup"); return(false); } }
private void Finish() { try{ MyToolkit.ActivityLog("Finished patching."); Progress.Value = 100; timer1.Enabled = false; if (myWorker.ErrorMessage != "") { txtErrors.Text = myWorker.ErrorMessage; webBrowser1.Visible = false; pnlErrors.Visible = true; } else { btnPlay.Enabled = true; cbManifest.Enabled = true; btnPlay.Text = "Play"; } } catch (Exception ex) { MyToolkit.ErrorReporter(ex, this.Name + ".Finish"); } }
/// <summary> /// Generates md5 checksum. /// </summary> /// <returns>MD5 checksum</returns> public string GenerateHash(string path) { try { MD5 md5Hash = MD5.Create(); var buffer = md5Hash.ComputeHash(File.ReadAllBytes(path)); var cs = new StringBuilder(); for (int i = 0; i < buffer.Length; i++) { cs.Append(buffer[i].ToString("x2")); } // Return an uppercase version of the consolidated string. return(cs.ToString().ToLower()); } catch (Exception ex) { MyToolkit.ErrorReporter(ex, "Fingerprint.GenerateHash"); return(""); } }
private void timer_Tick(object sender, EventArgs e) { try { if (myCopyObj != null) { if (myCopyObj.Active) { Progress.Value = myCopyObj.Progress; return; } } if (myWorker == null) { StartUp(); return; } if (myWorker.ForumURL != "" && myWorker.ForumURL != webBrowser1.Tag && myWorker.ForumURL != webBrowser1.Url.AbsoluteUri && !webBrowser1.IsBusy) { MyToolkit.ActivityLog("Loading Web Browser URL to: \"" + myWorker.ForumURL + "\""); webBrowser1.Tag = myWorker.ForumURL; webBrowser1.Navigate(myWorker.ForumURL); } if (myWorker.Manifest != null) { if (ListBox1.Items.Count <= 1) { IEnumerable <XElement> Profiles = myWorker.Manifest.Descendants("launch"); List <object> items = new List <object>(); foreach (XElement profile in Profiles) { var landingPage = profile.Attribute("landingPage"); var landingPageUri = new Uri(landingPage?.Value ?? "about:blank"); items.Add(new LaunchProfile(profile.Value.ToString().Replace("My App: ", "").Trim(), profile.Attribute("exec").Value, profile.Attribute("params").Value, landingPageUri)); } if (DevMode) { Profiles = myWorker.Manifest.Descendants("devlaunch"); foreach (XElement profile in Profiles) { var landingPage = profile.Attribute("landingPage"); var landingPageUri = new Uri(landingPage?.Value ?? "about:blank"); items.Add(new LaunchProfile(profile.Value.ToString().Replace("My App: ", "").Trim(), profile.Attribute("exec").Value, profile.Attribute("params").Value, landingPageUri)); } } ListBox1.DisplayMember = "Text"; ListBox1.DataSource = items; ListBox1.SelectedIndex = 0; } } Progress.Value = MyToolkit.MinMax(myWorker.CurProgress, 0, 100); lblStatus.Text = myWorker.Status + "... " + myWorker.CurFile; if (myWorker.Status == "Done") { Finish(); } } catch (Exception ex) { MyToolkit.ErrorReporter(ex, this.Name + ".Form_Load"); } }