private void MainForm_Shown(object sender, EventArgs e) { if (!(Program.FirstRun || Program.OfflineMode) && Program.LoncherSettings.Survey != null && YU.stringHasText(Program.LoncherSettings.Survey.Text) && YU.stringHasText(Program.LoncherSettings.Survey.Url) && YU.stringHasText(Program.LoncherSettings.Survey.ID) && (LauncherConfig.LastSurveyId is null || LauncherConfig.LastSurveyId != Program.LoncherSettings.Survey.ID)) { int showSurvey = new Random().Next(0, 100); string discardId = "-0" + Program.LoncherSettings.Survey.ID; bool wasDiscarded = discardId.Equals(LauncherConfig.LastSurveyId); if ((!wasDiscarded && showSurvey > 70) || (showSurvey > 7 && showSurvey < 10)) { DialogResult result = YobaDialog.ShowDialog(Program.LoncherSettings.Survey.Text, YobaDialog.YesNoBtns); if (result == DialogResult.Yes) { Process.Start(Program.LoncherSettings.Survey.Url); LauncherConfig.LastSurveyId = Program.LoncherSettings.Survey.ID; LauncherConfig.Save(); } else if (result == DialogResult.No) { LauncherConfig.LastSurveyId = discardId; LauncherConfig.Save(); } } } }
internal static void ShowHelpDialog() { if (Program.Disclaimer.Length > 0) { YobaDialog helpDialog = new YobaDialog(Program.VersionInfo, new Size(400, 400)); RichTextBox rtb = new RichTextBox(); rtb.BorderStyle = BorderStyle.None; rtb.Font = new Font("Verdana", 12F, FontStyle.Regular, GraphicsUnit.Pixel); //rtb.BackColor = Color.DimGray; //rtb.ForeColor = Color.White; rtb.ForeColor = Color.Black; rtb.BackColor = Color.LightGray; rtb.Location = new Point(16, 120); rtb.ReadOnly = true; rtb.Size = new Size(368, 224); rtb.TabIndex = 2; rtb.Text = Program.Disclaimer; rtb.LinkClicked += (sa, ea) => { Process.Start(ea.LinkText); }; helpDialog.MessageLabel.Size = new Size(helpDialog.Size.Width - 56, 92); helpDialog.Controls.Add(rtb); helpDialog.Shown += (o, e) => { helpDialog.ResetWinStyle(); }; helpDialog.ShowDialog(); } else { YobaDialog.ShowDialog(Program.VersionInfo); } }
public static void ErrorAndKill(string msg) { if (YobaDialog.ShowDialog(msg) != DialogResult.Ignore) { Application.Exit(); } }
private void settingsButton_Click(object sender, EventArgs e) { SettingsDialog settingsDialog = new SettingsDialog(this); settingsDialog.Icon = Program.LoncherSettings.Icon; if (settingsDialog.ShowDialog(this) == DialogResult.OK) { LauncherConfig.StartPage = settingsDialog.OpeningPanel; LauncherConfig.GameDir = settingsDialog.GamePath; LauncherConfig.LaunchFromGalaxy = settingsDialog.LaunchViaGalaxy; bool prevOffline = LauncherConfig.StartOffline; LauncherConfig.StartOffline = settingsDialog.OfflineMode; LauncherConfig.CloseOnLaunch = settingsDialog.CloseOnLaunch; LauncherConfig.Save(); settingsDialog.Dispose(); if (LauncherConfig.GameDir != Program.GamePath) { Hide(); new PreloaderForm(this).Show(); } else if (prevOffline != LauncherConfig.StartOffline) { if (YobaDialog.ShowDialog(Locale.Get(LauncherConfig.StartOffline ? "OfflineModeSet" : "OnlineModeSet"), YobaDialog.YesNoBtns) == DialogResult.Yes) { Hide(); new PreloaderForm(this).Show(); } } } this.Focus(); }
private void ShowDownloadError(string error) { YobaDialog.ShowDialog(error); launchGameButton.Enabled = true; updateProgressBar.Value = 0; updateLabelText.Text = Locale.Get("StatusDownloadError"); UpdateStatusWebView(); }
public static void SaveMods() { try { File.WriteAllText(MODINFOFILE, JsonConvert.SerializeObject(InstalledMods)); } catch (Exception ex) { YobaDialog.ShowDialog(Locale.Get("CannotWriteCfg") + ":\r\n" + ex.Message); } }
private void MakeBackupBtn_MouseClick(object sender, MouseEventArgs e) { string bkpdir = Program.GamePath + "_loncher_backups\\" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + "\\"; if (DialogResult.Yes == YobaDialog.ShowDialog(String.Format(Locale.Get("SettingsMakeBackupInfo"), bkpdir), YesNoBtns)) { try { string origDir = Program.GamePath; if (!Directory.Exists(bkpdir)) { Directory.CreateDirectory(bkpdir); } List <string> dirs = new List <string>(); void backupFile(FileInfo fi) { string path = fi.Path.Replace('/', '\\'); int fileNameStart = path.LastIndexOf('\\'); if (fileNameStart > 0) { string dir = path.Substring(0, fileNameStart); if (!dirs.Contains(dir)) { if (!Directory.Exists(bkpdir + dir)) { Directory.CreateDirectory(bkpdir + dir); } dirs.Add(dir); } } if (IOFile.Exists(origDir + path)) { IOFile.Copy(origDir + path, bkpdir + path); } } GameVersion gameVersion = Program.LoncherSettings.GameVersion; foreach (FileGroup fg in gameVersion.FileGroups) { foreach (FileInfo fi in fg.Files) { backupFile(fi); } } foreach (FileInfo fi in gameVersion.Files) { backupFile(fi); } YobaDialog.ShowDialog(String.Format(Locale.Get("SettingsMakeBackupDone"), bkpdir)); } catch (Exception ex) { YobaDialog.ShowDialog(ex.Message); } } }
public void UninstallMod(string id) { ModInfo mi = ModMap[id]; if (DialogResult.Yes == YobaDialog.ShowDialog(String.Format(Locale.Get("AreYouSureUninstallMod"), mi.Name), YobaDialog.YesNoBtns)) { mi.Delete(); Form.UpdateModsWebView(); } }
public void EnableMod(string id) { ModInfo mi = ModMap[id]; try { mi.Enable(); } catch (Exception ex) { YobaDialog.ShowDialog(String.Format(Locale.Get("CannotEnableMod"), mi.Name) + "\r\n\r\n" + ex.Message); } Form.UpdateModsWebView(); }
private bool findGamePath() { string path = LauncherConfig.GameDir; if (path is null) { path = getSteamGameInstallPath(); if (path is null && YU.stringHasText(Program.LoncherSettings.SteamGameFolder)) { List <string> steampaths = getSteamLibraryPaths(); for (int i = 0; i < steampaths.Count; i++) { string spath = steampaths[i] + Program.LoncherSettings.SteamGameFolder; if (Directory.Exists(spath)) { path = spath + "\\"; break; } } } if (path is null) { path = getGogGameInstallPath(); if (path != null) { _GOGpath = "" + path; } } path = showPathSelection(path); } if (path is null || path.Length == 0) { path = Program.GamePath; } if (path[path.Length - 1] != '\\') { path += "\\"; } while (!File.Exists(path + Program.LoncherSettings.ExeName)) { YobaDialog.ShowDialog(Locale.Get("NoExeInPath")); path = showPathSelection(path); if (path is null) { return(false); } } Program.GamePath = path; YU.Log("GamePath: " + path); return(true); }
private async Task InstallModAsync(string id) { ModInfo mi = ModMap[id]; uint size = 0; if (mi.CurrentVersionFiles[0].Size == 0) { await FileChecker.CheckFiles(mi.CurrentVersionFiles); } foreach (FileInfo fi in mi.CurrentVersionFiles) { if (!fi.IsOK) { size += fi.Size; } } int sizePow = 0; while (size > 2000) { size /= 1024; sizePow++; } if (sizePow > 5) { sizePow = 5; } if (DialogResult.Yes == YobaDialog.ShowDialog(String.Format(Locale.Get("AreYouSureInstallMod"), mi.Name, size, sizeUnits[sizePow]), YobaDialog.YesNoBtns)) { if (Form.modFilesToUpload_ is null) { Form.modFilesToUpload_ = new LinkedList <FileInfo>(mi.CurrentVersionFiles); mi.DlInProgress = true; Form.UpdateModsWebView(); if (!Form.UpdateInProgress_) { Form.DownloadNextMod(); } } else { foreach (FileInfo fi in mi.CurrentVersionFiles) { Form.modFilesToUpload_.AddLast(fi); } mi.DlInProgress = true; Form.UpdateModsWebView(); } } }
public static void Save() { try { File.WriteAllLines(CFGFILE, new string[] { "path = " + GameDir , "startpage = " + (int)StartPage , "startviagalaxy = " + (LaunchFromGalaxy ? 1 : 0) , "offlinemode = " + (StartOffline ? 1 : 0) , "closeonlaunch = " + (CloseOnLaunch ? 1 : 0) , "lastsrvchk = " + LastSurveyId }); } catch (Exception ex) { YobaDialog.ShowDialog(Locale.Get("CannotWriteCfg") + ":\r\n" + ex.Message); } }
private void CreateShortcutBtn_MouseClick(object sender, MouseEventArgs e) { try { string filename = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Запускатр Боевых Братьев.lnk"; if (!IOFile.Exists(filename)) { WshShell wsh = new WshShell(); IWshShortcut shortcut = wsh.CreateShortcut(filename) as IWshShortcut; shortcut.Arguments = ""; shortcut.TargetPath = Application.ExecutablePath; shortcut.WorkingDirectory = Program.LoncherPath; shortcut.WindowStyle = 1; string iconFile = Program.LoncherDataPath + "shortcutIcon.ico"; bool validIconFile = IOFile.Exists(iconFile); if (!validIconFile) { string exename = Program.GamePath + Program.LoncherSettings.ExeName; if (IOFile.Exists(PreloaderForm.ICON_FILE)) { PngIconConverter.Convert(PreloaderForm.ICON_FILE, iconFile); validIconFile = true; } else if (IOFile.Exists(exename) && exename.EndsWith(".exe")) { Icon exeIcon = Icon.ExtractAssociatedIcon(exename); if (exeIcon != null) { Bitmap exeBmp = exeIcon.ToBitmap(); PngIconConverter.Convert(exeBmp, iconFile); validIconFile = true; } } } if (validIconFile) { shortcut.IconLocation = iconFile; } shortcut.Save(); } } catch (Exception ex) { YobaDialog.ShowDialog(ex.Message); } }
private List <string> getSteamLibraryPaths() { List <string> paths = new List <string>(); try { string steamInstallPath = ""; using (RegistryKey view64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)) { using (RegistryKey clsid64 = view64.OpenSubKey(@"SOFTWARE\WOW6432Node\Valve\Steam")) { if (clsid64 != null) { steamInstallPath = (string)clsid64.GetValue("InstallPath"); } } } if (steamInstallPath.Length > 0) { paths.Add(steamInstallPath + @"\steamapps\common\"); string vdfPath = steamInstallPath + @"\steamapps\libraryfolders.vdf"; if (File.Exists(vdfPath)) { string[] lines = File.ReadAllLines(vdfPath); foreach (string line in lines) { if (line.Length > 0 && line.StartsWith("\t\"")) { string val = line.Substring(3); if (val.Length > 0 && val.StartsWith("\"\t\t\"")) { val = val.Substring(4, val.Length - 5); if (val.Length > 2 && val.Substring(1, 2) == ":\\") { paths.Add(val.Replace("\\\\", "\\") + @"\steamapps\common\"); } } } } } } } catch (Exception ex) { YobaDialog.ShowDialog(ex.Message); } return(paths); }
private string showPathSelection(string path) { if (!YU.stringHasText(path)) { path = Program.GamePath; } GamePathSelectForm gamePathSelectForm = new GamePathSelectForm(); gamePathSelectForm.Icon = Program.LoncherSettings.Icon; gamePathSelectForm.ThePath = path; if (gamePathSelectForm.ShowDialog(this) == DialogResult.Yes) { path = gamePathSelectForm.ThePath; gamePathSelectForm.Dispose(); if (path != null && path.Equals(_GOGpath) && LauncherConfig.GalaxyDir != null) { if (YobaDialog.ShowDialog(Locale.Get("GogGalaxyDetected"), YobaDialog.YesNoBtns) == DialogResult.Yes) { LauncherConfig.LaunchFromGalaxy = true; LauncherConfig.Save(); } } if (path.Length == 0) { path = Program.GamePath; } else { if (path[path.Length - 1] != '\\') { path += "\\"; } Program.GamePath = path; } LauncherConfig.GameDir = path; LauncherConfig.Save(); return(path); } else { Application.Exit(); return(null); } }
public static void Load() { GalaxyDir = YU.GetGogGalaxyPath(); try { if (File.Exists(CFGFILE)) { string[] lines = File.ReadAllLines(CFGFILE); foreach (string line in lines) { if (line.Length > 0) { if (line.StartsWith("path")) { string[] vals = line.Split('='); if (vals.Length > 1) { GameDir = vals[1].Trim(); } } else if (line.StartsWith("startpage")) { string[] vals = line.Split('='); if (vals.Length > 1) { if (int.TryParse(vals[1].Trim(), out int intval) && intval > -1 && intval < 4) { StartPage = (StartPageEnum)intval; } } } else if (line.StartsWith("lastsrvchk")) { string[] vals = line.Split('='); if (vals.Length > 1) { LastSurveyId = vals[1].Trim(); } } else if (line.StartsWith("startviagalaxy")) { if (GalaxyDir != null) { LaunchFromGalaxy = ParseBooleanParam(line); } } else if (line.StartsWith("offlinemode")) { StartOffline = ParseBooleanParam(line); } else if (line.StartsWith("closeonlaunch")) { CloseOnLaunch = ParseBooleanParam(line); } } } } if (File.Exists(MODINFOFILE)) { InstalledMods = JsonConvert.DeserializeObject <List <ModCfgInfo> >(File.ReadAllText(MODINFOFILE)); List <string> names = new List <string>(); for (int i = InstalledMods.Count - 1; i > -1; i--) { ModCfgInfo mci = InstalledMods[i]; if (names.FindIndex(x => x.Equals(mci.Name)) > -1) { InstalledMods.RemoveAt(i); } else { names.Add(mci.Name); } } } } catch (Exception ex) { YobaDialog.ShowDialog(Locale.Get("CannotReadCfg") + ":\r\n" + ex.Message); } }
private async void Initialize() { _progressBar1.Value = 0; Program.OfflineMode = false; long startingTicks = DateTime.Now.Ticks; long lastTicks = startingTicks; void logDeltaTicks(string point) { long current = DateTime.Now.Ticks; YU.Log(point + ": " + (current - lastTicks) + " (" + (current - startingTicks) + ')'); lastTicks = current; } try { if (!Directory.Exists(IMGPATH)) { Directory.CreateDirectory(IMGPATH); } if (!Directory.Exists(UPDPATH)) { Directory.CreateDirectory(UPDPATH); } //WebBrowserHelper.FixBrowserVersion(); //ErrorAndKill("Cannot get Images:\r\n"); string settingsJson = (await wc_.DownloadStringTaskAsync(Program.SETTINGS_URL)); logDeltaTicks("settings"); incProgress(5); try { Program.LoncherSettings = new LauncherData(settingsJson); try { File.WriteAllText(SETTINGSPATH, settingsJson, Encoding.UTF8); } catch { } incProgress(5); try { if (Program.LoncherSettings.RAW.Localization != null) { FileInfo locInfo = Program.LoncherSettings.RAW.Localization; if (YU.stringHasText(locInfo.Url)) { locInfo.Path = LOCPATH; if (!FileChecker.CheckFileMD5("", locInfo)) { string loc = await wc_.DownloadStringTaskAsync(locInfo.Url); File.WriteAllText(LOCPATH, loc, Encoding.UTF8); Locale.LoadCustomLoc(loc.Replace("\r\n", "\n").Split('\n')); } Locale.LoadCustomLoc(File.ReadAllLines(LOCPATH, Encoding.UTF8)); } else if (File.Exists(LOCPATH)) { Locale.LoadCustomLoc(File.ReadAllLines(LOCPATH, Encoding.UTF8)); } } else if (File.Exists(LOCPATH)) { Locale.LoadCustomLoc(File.ReadAllLines(LOCPATH, Encoding.UTF8)); } incProgress(5); logDeltaTicks("locales"); } catch (Exception ex) { YobaDialog.ShowDialog(Locale.Get("CannotGetLocaleFile") + ":\r\n" + ex.Message); } try { downloadProgressTracker_ = new DownloadProgressTracker(50, TimeSpan.FromMilliseconds(500)); wc_.DownloadProgressChanged += new DownloadProgressChangedEventHandler(OnDownloadProgressChanged); #if DEBUG #else if (YU.stringHasText(Program.LoncherSettings.LoncherHash)) { string selfHash = FileChecker.GetFileMD5(Application.ExecutablePath); if (!Program.LoncherSettings.LoncherHash.ToUpper().Equals(selfHash)) { if (YU.stringHasText(Program.LoncherSettings.LoncherExe)) { string newLoncherPath = Application.ExecutablePath + ".new"; string appname = Application.ExecutablePath; appname = appname.Substring(appname.LastIndexOf('\\') + 1); await loadFile(Program.LoncherSettings.LoncherExe, newLoncherPath, Locale.Get("UpdatingLoncher")); string newHash = FileChecker.GetFileMD5(newLoncherPath); if (selfHash.Equals(Program.PreviousVersionHash)) { YU.ErrorAndKill(Locale.Get("LoncherOutOfDate2")); } else if (newHash.Equals(Program.PreviousVersionHash)) { YU.ErrorAndKill(Locale.Get("LoncherOutOfDate3")); } else { Process.Start(new ProcessStartInfo { Arguments = String.Format("/C choice /C Y /N /D Y /T 1 & Del \"{0}\" & Rename \"{1}\" \"{2}\" & \"{0}\" -oldhash {3}" , Application.ExecutablePath, newLoncherPath, appname, selfHash) , FileName = "cmd" , WindowStyle = ProcessWindowStyle.Hidden }); Application.Exit(); } return; } else { YU.ErrorAndKill(Locale.Get("LoncherOutOfDate1")); return; } } } #endif } catch (Exception ex) { YU.ErrorAndKill(Locale.Get("CannotUpdateLoncher") + ":\r\n" + ex.Message + "\r\n" + ex.StackTrace); return; } LauncherData.LauncherDataRaw launcherDataRaw = Program.LoncherSettings.RAW; try { if (await assertFile(launcherDataRaw.Icon, IMGPATH, ICON_FILE)) { Bitmap bm = YU.readBitmap(ICON_FILE); if (bm != null) { Program.LoncherSettings.Icon = Icon.FromHandle(bm.GetHicon()); this.Icon = Program.LoncherSettings.Icon; } } if (Program.LoncherSettings.Icon == null) { Program.LoncherSettings.Icon = this.Icon; } if (await assertFile(launcherDataRaw.PreloaderBackground, IMGPATH, BG_FILE)) { this.BackgroundImage = YU.readBitmap(BG_FILE); } bool gotRandomBG = false; if (launcherDataRaw.RandomBackgrounds != null && launcherDataRaw.RandomBackgrounds.Count > 0) { int randomBGRoll = new Random().Next(0, 1000); int totalRoll = 0; foreach (RandomBgImageInfo rbgi in launcherDataRaw.RandomBackgrounds) { if (await assertFile(rbgi.Background, IMGPATH)) { totalRoll += rbgi.Chance; if (totalRoll > randomBGRoll) { Program.LoncherSettings.Background = YU.readBitmap(IMGPATH + rbgi.Background.Path); gotRandomBG = true; break; } } } } if (!gotRandomBG && await assertFile(launcherDataRaw.Background, IMGPATH)) { Program.LoncherSettings.Background = YU.readBitmap(IMGPATH + launcherDataRaw.Background.Path); } if (Program.LoncherSettings.UI.Count > 0) { string[] keys = Program.LoncherSettings.UI.Keys.ToArray(); foreach (string key in keys) { if (!(await assertFile(Program.LoncherSettings.UI[key].BgImage, IMGPATH))) { Program.LoncherSettings.UI[key].BgImage = null; } if (!(await assertFile(Program.LoncherSettings.UI[key].BgImageClick, IMGPATH))) { Program.LoncherSettings.UI[key].BgImageClick = null; } if (!(await assertFile(Program.LoncherSettings.UI[key].BgImageHover, IMGPATH))) { Program.LoncherSettings.UI[key].BgImageHover = null; } } } if (Program.LoncherSettings.Buttons.Count > 0) { foreach (LinkButton lbtn in Program.LoncherSettings.Buttons) { if (!(await assertFile(lbtn.BgImage, IMGPATH))) { lbtn.BgImage = null; } if (!(await assertFile(lbtn.BgImageClick, IMGPATH))) { lbtn.BgImageClick = null; } if (!(await assertFile(lbtn.BgImageHover, IMGPATH))) { lbtn.BgImageHover = null; } } } /*await assertFile(new FileInfo() { * Url = "https://drive.google.com/uc?export=download&confirm=-MpP&id=1fUW0NfP2EYUG6K2hOg6hgajRi59pCBBy" * , Path = "legends" * }, IMGPATH);*/ logDeltaTicks("images"); } catch (Exception ex) { YU.ErrorAndKill(Locale.Get("CannotGetImages") + ":\r\n" + ex.Message); return; } if (Program.LoncherSettings.Fonts != null) { List <string> keys = Program.LoncherSettings.Fonts.Keys.ToList(); if (keys.Count > 0) { try { if (!Directory.Exists(FNTPATH)) { Directory.CreateDirectory(FNTPATH); } foreach (string key in keys) { using (Font fontTester = new Font(key, 12, FontStyle.Regular, GraphicsUnit.Pixel)) { if (fontTester.Name == key) { Program.LoncherSettings.Fonts[key] = "win"; } else if (File.Exists(FNTPATH + key)) { Program.LoncherSettings.Fonts[key] = "local"; } else { string status = "none"; string src = Program.LoncherSettings.Fonts[key]; string filename = FNTPATH + key; if (YU.stringHasText(src)) { await loadFile(src, filename); if (File.Exists(filename)) { status = "local"; } } Program.LoncherSettings.Fonts[key] = status; } } } logDeltaTicks("fonts"); } catch (Exception ex) { YU.ErrorAndKill(Locale.Get("CannotGetFonts") + ":\r\n" + ex.Message); return; } } } try { loadingLabel.Text = Locale.Get("PreparingToLaunch"); //await Program.LoncherSettings.InitChangelogOnline(); Program.LoncherSettings.Changelog = await getStaticTabData("Changelog", launcherDataRaw.Changelog, launcherDataRaw.QuoteToEscape, "[[[CHANGELOG]]]"); Program.LoncherSettings.FAQ = await getStaticTabData("FAQ", launcherDataRaw.FAQFile, launcherDataRaw.QuoteToEscape, "[[[FAQTEXT]]]"); incProgress(5); logDeltaTicks("changelog and etc"); //loadingLabel.Text = Locale.Get("PreparingToLaunch"); try { if (findGamePath()) { try { updateGameVersion(); if (oldMainForm_ != null) { oldMainForm_.Dispose(); } int progressBarPerFile = 100 - _progressBar1.Value; if (progressBarPerFile < Program.LoncherSettings.Files.Count) { progressBarPerFile = 88; _progressBar1.Value = 6; } progressBarPerFile = progressBarPerFile / Program.LoncherSettings.Files.Count; if (progressBarPerFile < 1) { progressBarPerFile = 1; } Program.GameFileCheckResult = await FileChecker.CheckFiles( Program.LoncherSettings.Files , new EventHandler <FileCheckedEventArgs>((object o, FileCheckedEventArgs a) => { _progressBar1.Value += progressBarPerFile; if (_progressBar1.Value > 100) { _progressBar1.Value = 40; } }) ); foreach (ModInfo mi in Program.LoncherSettings.Mods) { if (mi.ModConfigurationInfo != null) { await FileChecker.CheckFiles( mi.CurrentVersionFiles , new EventHandler <FileCheckedEventArgs>((object o, FileCheckedEventArgs a) => { _progressBar1.Value += progressBarPerFile; if (_progressBar1.Value > 100) { _progressBar1.Value = 40; } }) ); } } logDeltaTicks("filecheck"); showMainForm(); } catch (Exception ex) { YU.ErrorAndKill(Locale.Get("CannotCheckFiles") + ":\r\n" + ex.Message); } } } catch (Exception ex) { YU.ErrorAndKill(Locale.Get("CannotParseConfig") + ":\r\n" + ex.Message); } } catch (Exception ex) { YU.ErrorAndKill(Locale.Get("CannotLoadIcon") + ":\r\n" + ex.Message); } } catch (Exception ex) { YU.ErrorAndKill(Locale.Get("CannotParseSettings") + ":\r\n" + ex.Message); } } catch (Exception ex) { UIElement[] btns; UIElement btnQuit = new UIElement(); btnQuit.Caption = Locale.Get("Quit"); btnQuit.Result = DialogResult.Abort; UIElement btnRetry = new UIElement(); btnRetry.Caption = Locale.Get("Retry"); btnRetry.Result = DialogResult.Retry; string msg; if (File.Exists(SETTINGSPATH)) { msg = Locale.Get("WebClientErrorOffline"); UIElement btnOffline = new UIElement(); btnOffline.Caption = Locale.Get("RunOffline"); btnOffline.Result = DialogResult.Ignore; btns = new UIElement[] { btnQuit, btnRetry, btnOffline }; } else { msg = Locale.Get("WebClientError"); btns = new UIElement[] { btnQuit, btnRetry }; } YobaDialog yobaDialog = new YobaDialog(msg, btns); yobaDialog.Icon = Program.LoncherSettings != null ? (Program.LoncherSettings.Icon ?? this.Icon) : this.Icon; DialogResult result = yobaDialog.ShowDialog(this); switch (result) { case DialogResult.Retry: Initialize(); break; case DialogResult.Ignore: InitializeOffline(); break; case DialogResult.Abort: { Application.Exit(); return; } } } }
private void InitializeOffline() { try { Program.OfflineMode = true; string settingsJson = File.ReadAllText(SETTINGSPATH); Program.LoncherSettings = new LauncherData(settingsJson); LauncherData.LauncherDataRaw launcherDataRaw = Program.LoncherSettings.RAW; incProgress(10); try { try { if (File.Exists(LOCPATH)) { Locale.LoadCustomLoc(File.ReadAllLines(LOCPATH, Encoding.UTF8)); } } catch (Exception ex) { YobaDialog.ShowDialog(Locale.Get("CannotGetLocaleFile") + ":\r\n" + ex.Message); } if (assertOfflineFile(launcherDataRaw.Background, IMGPATH)) { Program.LoncherSettings.Background = YU.readBitmap(IMGPATH + launcherDataRaw.Background.Path); } if (assertOfflineFile(launcherDataRaw.Icon, IMGPATH, ICON_FILE)) { Bitmap bm = YU.readBitmap(IMGPATH + launcherDataRaw.Icon.Path); if (bm != null) { Program.LoncherSettings.Icon = Icon.FromHandle(bm.GetHicon()); } } if (assertOfflineFile(launcherDataRaw.PreloaderBackground, IMGPATH, BG_FILE)) { this.BackgroundImage = YU.readBitmap(IMGPATH + launcherDataRaw.PreloaderBackground.Path); } if (Program.LoncherSettings.Icon == null) { Program.LoncherSettings.Icon = this.Icon; } if (Program.LoncherSettings.UI.Count > 0) { string[] keys = Program.LoncherSettings.UI.Keys.ToArray(); foreach (string key in keys) { if (!(assertOfflineFile(Program.LoncherSettings.UI[key].BgImage, IMGPATH))) { Program.LoncherSettings.UI[key].BgImage = null; } } } if (Program.LoncherSettings.Buttons.Count > 0) { foreach (LinkButton lbtn in Program.LoncherSettings.Buttons) { if (!(assertOfflineFile(lbtn.BgImage, IMGPATH))) { lbtn.BgImage = null; } } } } catch (Exception ex) { YU.ErrorAndKill(Locale.Get("CannotGetImages") + ":\r\n" + ex.Message); return; } if (Program.LoncherSettings.Fonts != null) { List <string> keys = Program.LoncherSettings.Fonts.Keys.ToList(); if (keys.Count > 0) { try { if (!Directory.Exists(FNTPATH)) { Directory.CreateDirectory(FNTPATH); } foreach (string key in keys) { using (Font fontTester = new Font(key, 12, FontStyle.Regular, GraphicsUnit.Pixel)) { if (fontTester.Name == key) { Program.LoncherSettings.Fonts[key] = "win"; } else if (File.Exists(FNTPATH + key)) { Program.LoncherSettings.Fonts[key] = "local"; } else { Program.LoncherSettings.Fonts[key] = "none"; } } } } catch (Exception ex) { YU.ErrorAndKill(Locale.Get("CannotGetFonts") + ":\r\n" + ex.Message); return; } } } try { try { Program.LoncherSettings.Changelog = getStaticTabDataOffline("Changelog", launcherDataRaw.Changelog, launcherDataRaw.QuoteToEscape, "[[[CHANGELOG]]]"); Program.LoncherSettings.FAQ = getStaticTabDataOffline("FAQ", launcherDataRaw.FAQFile, launcherDataRaw.QuoteToEscape, "[[[FAQTEXT]]]"); if (findGamePath()) { try { updateGameVersion(); incProgress(10); Program.GameFileCheckResult = FileChecker.CheckFilesOffline(Program.LoncherSettings.Files); foreach (ModInfo mi in Program.LoncherSettings.Mods) { if (mi.ModConfigurationInfo != null) { FileChecker.CheckFilesOffline(mi.CurrentVersionFiles); } } showMainForm(); } catch (Exception ex) { YU.ErrorAndKill(Locale.Get("CannotCheckFiles") + ":\r\n" + ex.Message); } } } catch (Exception ex) { YU.ErrorAndKill(Locale.Get("CannotParseConfig") + ":\r\n" + ex.Message); } } catch (Exception ex) { YU.ErrorAndKill(Locale.Get("CannotLoadIcon") + ":\r\n" + ex.Message); } } catch (Exception ex) { YU.ErrorAndKill(Locale.Get("CannotParseSettings") + ":\r\n" + ex.Message); } }
private void DownloadNext() { do { currentFile_ = currentFile_.Next; }while ((currentFile_ != null) && !currentFile_.Value.IsCheckedToDl); if (currentFile_ != null) { DownloadFile(currentFile_.Value); } else { string filename = ""; updateProgressBar.Value = 100; updateLabelText.Text = Locale.Get("StatusCopyingFiles"); try { foreach (FileInfo fileInfo in filesToUpload_) { if (!fileInfo.IsCheckedToDl) { continue; } filename = ThePath + fileInfo.Path.Replace('/', '\\'); string dirpath = filename.Substring(0, filename.LastIndexOf('\\')); Directory.CreateDirectory(dirpath); if (File.Exists(filename)) { File.Delete(filename); } File.Move(PreloaderForm.UPDPATH + fileInfo.UploadAlias, filename); fileInfo.IsOK = true; fileInfo.IsPresent = true; } updateLabelText.Text = Locale.Get("StatusUpdatingDone"); UpdateStatusWebView(); if (modFilesToUpload_ != null) { UpdateInProgress_ = false; DownloadNextMod(); } else { SetReady(true); launchGameButton.Enabled = true; UpdateInProgress_ = false; if (YobaDialog.ShowDialog(Locale.Get("UpdateSuccessful"), YobaDialog.YesNoBtns) == DialogResult.Yes) { launch(); } } } catch (UnauthorizedAccessException ex) { ShowDownloadError(string.Format(Locale.Get("DirectoryAccessDenied"), filename) + ":\r\n" + ex.Message); } catch (Exception ex) { ShowDownloadError(string.Format(Locale.Get("CannotMoveFile"), filename) + ":\r\n" + ex.Message); } UpdateInProgress_ = false; } }
public MainForm() { ThePath = Program.GamePath; InitializeComponent(); int winstyle = NativeWinAPI.GetWindowLong(basePanel.Handle, NativeWinAPI.GWL_EXSTYLE); NativeWinAPI.SetWindowLong(basePanel.Handle, NativeWinAPI.GWL_EXSTYLE, winstyle | NativeWinAPI.WS_EX_COMPOSITED); SuspendLayout(); wc_ = new WebClient { Encoding = Encoding.UTF8 }; wc_.DownloadProgressChanged += new DownloadProgressChangedEventHandler(OnDownloadProgressChanged); wc_.DownloadFileCompleted += new AsyncCompletedEventHandler(OnDownloadCompleted); downloadProgressTracker_ = new DownloadProgressTracker(50, TimeSpan.FromMilliseconds(500)); int missingFilesCount = Program.GameFileCheckResult.InvalidFiles.Count; if (missingFilesCount > 0) { filesToUpload_ = Program.GameFileCheckResult.InvalidFiles; bool allowRun = true; foreach (FileInfo fi in filesToUpload_) { if (fi.Importance < 2 && (!fi.IsPresent || (!fi.IsOK && fi.Importance < 1))) { allowRun = false; } else { missingFilesCount--; } } SetReady(allowRun); } else { SetReady(true); } updateLabelText.Text = ReadyToGo_ ? Locale.Get("AllFilesIntact") : String.Format(Locale.Get("FilesMissing"), missingFilesCount); changelogMenuBtn.Text = Locale.Get("ChangelogBtn"); linksButton.Text = Locale.Get("LinksBtn"); settingsButton.Text = Locale.Get("SettingsBtn"); faqButton.Text = Locale.Get("FAQBtn"); statusButton.Text = Locale.Get("StatusBtn"); modsButton.Text = Locale.Get("ModsBtn"); Text = Locale.Get("MainFormTitle"); theToolTip.SetToolTip(closeButton, Locale.Get("Close")); theToolTip.SetToolTip(minimizeButton, Locale.Get("Minimize")); theToolTip.SetToolTip(changelogMenuBtn, Locale.Get("ChangelogTooltip")); theToolTip.SetToolTip(statusButton, Locale.Get("StatusTooltip")); theToolTip.SetToolTip(linksButton, Locale.Get("LinksTooltip")); theToolTip.SetToolTip(settingsButton, Locale.Get("SettingsTooltip")); theToolTip.SetToolTip(faqButton, Locale.Get("FAQTooltip")); theToolTip.SetToolTip(modsButton, Locale.Get("ModsTooltip")); uiPanels_ = new Panel[] { changelogPanel, statusPanel, linksPanel, modsPanel, faqPanel }; foreach (Panel p in uiPanels_) { p.Location = new Point(0, 0); p.Size = new Size(610, 330); } allowUrlsInEmbeddedBrowser.Add(statusBrowser, false); allowUrlsInEmbeddedBrowser.Add(modsBrowser, false); allowUrlsInEmbeddedBrowser.Add(faqBrowser, false); allowUrlsInEmbeddedBrowser.Add(changelogBrowser, false); UpdateInfoWebViews(); statusBrowser.Size = new Size(610, 330); statusBrowser.Location = new Point(0, 0); modsBrowser.Size = new Size(610, 330); modsBrowser.Location = new Point(0, 0); statusBrowser.ObjectForScripting = StatusController.Instance; StatusController.Instance.Form = this; StatusController.Instance.FileMap = new Dictionary <string, FileInfo>(); modsBrowser.ObjectForScripting = ModsController.Instance; ModsController.Instance.Form = this; UpdateStatusWebView(); UpdateModsWebView(); if (Program.LoncherSettings.UI.ContainsKey("UpdateLabel")) { UIElement updateLabelInfo = Program.LoncherSettings.UI["UpdateLabel"]; if (updateLabelInfo != null) { updateLabelText.BackColor = YU.colorFromString(updateLabelInfo.BgColor, Color.Transparent); updateLabelText.ForeColor = YU.colorFromString(updateLabelInfo.Color, Color.White); YU.setFont(updateLabelText, updateLabelInfo.Font, updateLabelInfo.FontSize); } } string[] menuScreenKeys = new string[] { "BasePanel", "StatusPanel", "LinksPanel", "ModsPanel", "ChangelogPanel", "FAQPanel" }; string[] menuBtnKeys = new string[] { "LaunchButton", "SettingsButton", "StatusButton", "LinksButton", "ChangelogButton", "ModsButton", "FAQButton", "CloseButton", "MinimizeButton", "HelpButton" }; string[] menuBtnControlKeys = new string[] { "launchGameButton", "settingsButton", "statusButton", "linksButton", "changelogMenuBtn", "modsButton", "faqButton", "closeButton", "minimizeButton", "helpButton" }; for (int i = 0; i < menuBtnKeys.Length; i++) { string menuBtnKey = menuBtnKeys[i]; if (Program.LoncherSettings.UI.ContainsKey(menuBtnKey)) { UIElement launchButtonInfo = Program.LoncherSettings.UI[menuBtnKey]; if (launchButtonInfo != null) { Control[] ctrls = Controls.Find(menuBtnControlKeys[i], true); if (ctrls.Length > 0) { ((YobaButtonAbs)ctrls[0]).ApplyUIStyles(launchButtonInfo); } } } } foreach (string menuScreenKey in menuScreenKeys) { if (Program.LoncherSettings.UI.ContainsKey(menuScreenKey)) { UIElement uiInfo = Program.LoncherSettings.UI[menuScreenKey]; if (uiInfo != null) { Control[] ctrls = Controls.Find(menuScreenKey, true); if (ctrls.Length > 0) { Panel panel = (Panel)ctrls[0]; if (uiInfo.Position != null) { panel.Location = new Point(uiInfo.Position.X, uiInfo.Position.Y); } if (uiInfo.Size != null) { panel.Size = new Size(uiInfo.Size.X, uiInfo.Size.Y); } if (YU.stringHasText(uiInfo.Color)) { panel.ForeColor = YU.colorFromString(uiInfo.Color, Color.White); } if (YU.stringHasText(uiInfo.BgColor)) { panel.BackColor = YU.colorFromString(uiInfo.BgColor, Color.DimGray); } if (uiInfo.BgImage != null && YU.stringHasText(uiInfo.BgImage.Path)) { if (YU.stringHasText(uiInfo.BgImage.Layout)) { try { Enum.Parse(typeof(ImageLayout), uiInfo.BgImage.Layout); } catch { panel.BackgroundImageLayout = ImageLayout.Stretch; } } else { panel.BackgroundImageLayout = ImageLayout.Stretch; } panel.BackgroundImage = YU.readBitmap(PreloaderForm.IMGPATH + uiInfo.BgImage.Path); } } } } } for (int i = 0; i < Program.LoncherSettings.Buttons.Count; i++) { LinkButton lbtn = Program.LoncherSettings.Buttons[i]; if (lbtn != null) { YobaButton linkButton = new YobaButton(lbtn.Url); linkButton.Name = "linkBtn" + (i + 1); linkButton.TabIndex = 10 + i; linkButton.UseVisualStyleBackColor = true; linkButton.ApplyUIStyles(lbtn); if (YU.stringHasText(lbtn.Caption)) { linkButton.Text = ""; theToolTip.SetToolTip(linkButton, lbtn.Caption); } linkButton.Click += new EventHandler((object o, EventArgs a) => { string url = ((YobaButton)o).Url; if (YU.stringHasText(url)) { Process.Start(url); } }); linksPanel.Controls.Add(linkButton); } } BackgroundImageLayout = ImageLayout.Stretch; BackgroundImage = Program.LoncherSettings.Background; switch (LauncherConfig.StartPage) { case StartPageEnum.Changelog: changelogPanel.Visible = true; break; case StartPageEnum.Mods: modsPanel.Visible = true; break; case StartPageEnum.Status: statusPanel.Visible = true; break; case StartPageEnum.Links: linksPanel.Visible = true; break; case StartPageEnum.FAQ: faqPanel.Visible = true; break; } List <ModInfo> outdatedMods = new List <ModInfo>(); LinkedList <FileInfo> outdatedModFiles = new LinkedList <FileInfo>(); LinkedList <FileInfo> outdatedAlteredModFiles = new LinkedList <FileInfo>(); foreach (ModInfo mi in Program.LoncherSettings.Mods) { if (mi.CurrentVersionFiles != null) { if ((mi.ModConfigurationInfo != null) && mi.ModConfigurationInfo.Active) { bool hasit = false; foreach (FileInfo mif in mi.CurrentVersionFiles) { if (!mif.IsOK) { outdatedModFiles.AddLast(mif); if (!hasit) { outdatedMods.Add(mi); hasit = true; } if (mi.ModConfigurationInfo.Altered) { outdatedAlteredModFiles.AddLast(mif); } } } if (hasit) { outdatedModFiles.Last.Value.LastFileOfModToUpdate = mi; } } } } if (outdatedMods.Count > 0) { string outdatedmods = ""; string alteredmods = ""; List <ModInfo> alteredOutdatedMods = new List <ModInfo>(); ulong outdatedmodssize = 0; bool comma = false; bool altcomma = false; foreach (ModInfo mi in outdatedMods) { if (!comma) { comma = true; } else { outdatedmods += ", "; } outdatedmods += mi.CurrentVersionData.Name ?? mi.Name; if (mi.ModConfigurationInfo.Altered) { if (!altcomma) { altcomma = true; } else { alteredmods += ", "; } alteredOutdatedMods.Add(mi); alteredmods += mi.CurrentVersionData.Name ?? mi.Name; } } foreach (FileInfo mif in outdatedModFiles) { outdatedmodssize += mif.Size; } if (DialogResult.Yes == YobaDialog.ShowDialog(String.Format(Locale.Get("YouHaveOutdatedMods"), outdatedmods, YU.formatFileSize(outdatedmodssize)), YobaDialog.YesNoBtns)) { modFilesToUpload_ = outdatedModFiles; foreach (ModInfo mi in outdatedMods) { mi.DlInProgress = true; } UpdateModsWebView(); if (!UpdateInProgress_) { DownloadNextMod(); } } else { if (alteredOutdatedMods.Count > 0) { ulong alteredmodssize = 0; foreach (FileInfo mif in outdatedAlteredModFiles) { alteredmodssize += mif.Size; } if (DialogResult.Yes == YobaDialog.ShowDialog(String.Format(Locale.Get("YouHaveAlteredMods"), alteredmods, YU.formatFileSize(alteredmodssize)), YobaDialog.YesNoBtns)) { modFilesToUpload_ = outdatedAlteredModFiles; foreach (ModInfo mi in alteredOutdatedMods) { mi.DlInProgress = true; } UpdateModsWebView(); if (!UpdateInProgress_) { DownloadNextMod(); } } } } } PerformLayout(); }