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(); } } } }
private bool assertOfflineFile(FileInfo fi, string dir, string targetPath) { if (fi != null && YU.stringHasText(fi.Path) && File.Exists(targetPath)) { return(true); } return(false); }
private async Task <bool> assertFile(FileInfo fi, string dir, string targetPath) { if (fi != null && YU.stringHasText(fi.Path) && YU.stringHasText(fi.Url)) { if (!FileChecker.CheckFileMD5(dir, fi)) { Directory.CreateDirectory(dir); await loadFile(fi.Url, targetPath); } return(true); } return(false); }
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); }
public override void ApplyUIStyles(UIElement styleInfo) { base.ApplyUIStyles(styleInfo); if (YU.stringHasText(styleInfo.FontSize)) { YU.setFont(this, styleInfo.Font, styleInfo.FontSize); } if (styleInfo.CustomStyle) { BackColor = YU.colorFromString(styleInfo.BgColor, Color.FromArgb(62, 63, 64)); FlatAppearance.BorderSize = styleInfo.BorderSize > -1 ? styleInfo.BorderSize : 0; FlatAppearance.MouseOverBackColor = YU.colorFromString(styleInfo.BgColorHover, BtnColors.Back); FlatAppearance.MouseDownBackColor = YU.colorFromString(styleInfo.BgColorDown, BtnColors.MouseDown); } }
private async void DownloadFile(FileInfo fileInfo) { if (!YU.stringHasText(fileInfo.UploadAlias)) { fileInfo.UploadAlias = fileInfo.Hashes.Count > 0 ? fileInfo.Hashes[0] : null; if (!YU.stringHasText(fileInfo.UploadAlias)) { int lios = Math.Max(fileInfo.Path.LastIndexOf('\\'), fileInfo.Path.LastIndexOf('/')); fileInfo.UploadAlias = lios > -1 ? fileInfo.Path.Substring(lios + 1, fileInfo.Path.Length) : fileInfo.Path; } } string uploadFilename = PreloaderForm.UPDPATH + fileInfo.UploadAlias; if (File.Exists(uploadFilename)) { if (FileChecker.CheckFileMD5(PreloaderForm.UPDPATH, fileInfo)) { if (UpdateInProgress_) { DownloadNext(); } else { DownloadNextMod(); } return; } else { File.Delete(uploadFilename); } } try { updateProgressBar.Value = 0; updateLabelText.Text = string.Format( Locale.Get("DLRate") , FormatBytes(0) , FormatBytes(fileInfo.Size) , "" , currentFile_.Value.Description ); await wc_.DownloadFileTaskAsync(new Uri(fileInfo.Url), uploadFilename); } catch (Exception ex) { ShowDownloadError(string.Format(Locale.Get("CannotDownloadFile"), fileInfo.Path) + "\r\n" + ex.Message); } }
public void LoadFileListForVersion(string curVer) { if (YU.stringHasText(curVer)) { if (GameVersions.ContainsKey(curVer)) { GameVersion = GameVersions[curVer]; } } if (GameVersion is null) { if (GameVersions.ContainsKey("DEFAULT")) { GameVersion = GameVersions["DEFAULT"]; } else if (GameVersions.ContainsKey("OTHER")) { GameVersion = GameVersions["OTHER"]; } } if (GameVersion is null) { throw new Exception(string.Format(Locale.Get("OldGameVersion"), curVer)); } foreach (FileGroup fileGroup in GameVersion.FileGroups) { if (fileGroup.Files != null) { Files.AddRange(fileGroup.Files); } } if (GameVersion.Files != null) { Files.AddRange(GameVersion.Files); } foreach (ModInfo mi in Mods) { mi.InitCurrentVersion(curVer); } foreach (string file in zzModFilesToDelete) { if (zzModFilesInUse.FindIndex(x => x.Equals(file)) < 0) { File.Delete(Program.GamePath + file); } } }
public LauncherData(string json) { LauncherDataRaw raw = JsonConvert.DeserializeObject <LauncherDataRaw>(json); raw_ = raw; wc_ = new WebClient(); wc_.Encoding = System.Text.Encoding.UTF8; Buttons = raw.Buttons ?? new List <LinkButton>(); foreach (LinkButton btn in Buttons) { if (btn.Position == null) { btn.Position = new Vector(); } if (btn.Size == null) { btn.Size = new Vector(); } } StartPage = raw.StartPage; UI = raw.UI ?? new Dictionary <string, UIElement>(); UIStyle = raw.UIStyle ?? new Dictionary <string, FileInfo>(); ExeName = raw.ExeName; SteamID = raw.SteamID; GogID = raw.GogID; LoncherHash = raw.LoncherHash; LoncherExe = raw.LoncherExe; Survey = raw.Survey; GameName = raw.GameName; SteamGameFolder = raw.SteamGameFolder; GameVersions = PrepareGameVersions(raw.GameVersions); if (raw.Mods != null && raw.Mods.Count > 0) { foreach (RawModInfo rmi in raw.Mods) { if (YU.stringHasText(rmi.Name) && rmi.GameVersions != null) { Mods.Add(new ModInfo(rmi.Name, rmi.Description, PrepareGameVersions(rmi.GameVersions))); } } } }
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); } }
private async Task <LauncherData.StaticTabData> getStaticTabData(string uiKey, string url, string quoteToEscape, string replacePlaceholder) { LauncherData.StaticTabData staticTabData = new LauncherData.StaticTabData(); staticTabData.Site = url; try { if (Program.LoncherSettings.UIStyle.TryGetValue(uiKey, out FileInfo fileInfo)) { if (fileInfo != null && YU.stringHasText(fileInfo.Url)) { using (WebClient wc = new WebClient { Encoding = Encoding.UTF8 }) { string template = (await wc.DownloadStringTaskAsync(new Uri(fileInfo.Url))); string cl = ""; if (url != null && url.Length > 0) { cl = (await wc.DownloadStringTaskAsync(new Uri(url))); if (quoteToEscape != null && quoteToEscape.Length > 0) { string quote = quoteToEscape; cl = cl.Replace("\\", "\\\\").Replace(quote, "\\" + quote); if (cl.Contains("\r")) { cl = cl.Replace("\r\n", "\\\r\n"); } else { cl = cl.Replace("\n", "\\\n"); } } } staticTabData.Html = template.Replace(replacePlaceholder, cl); } } } } catch (Exception ex) { staticTabData.Error = ex.Message; } return(staticTabData); }
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(); }
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; } } } }
public virtual void ApplyUIStyles(UIElement styleInfo) { StyleInfo = styleInfo; UseVisualStyleBackColor = true; if (styleInfo.Position != null) { Location = new Point(styleInfo.Position.X, styleInfo.Position.Y); } if (styleInfo.Size != null) { Size = new Size(styleInfo.Size.X, styleInfo.Size.Y); } if (styleInfo.Caption != null) { Text = styleInfo.Caption; } if (styleInfo.CustomStyle) { FlatStyle = FlatStyle.Flat; ForeColor = YU.colorFromString(styleInfo.Color, BtnColors.Fore); FlatAppearance.BorderColor = YU.colorFromString(styleInfo.BorderColor, BtnColors.Border); } if (styleInfo.BgImage != null && YU.stringHasText(styleInfo.BgImage.Path)) { styleInfo.BgImage.ImageLayout = ImageLayout.Stretch; if (YU.stringHasText(styleInfo.BgImage.Layout)) { if (Enum.TryParse(styleInfo.BgImage.Layout, out ImageLayout layout)) { styleInfo.BgImage.ImageLayout = layout; } } BackgroundImageLayout = styleInfo.BgImage.ImageLayout; BackgroundImage = YU.readBitmap(PreloaderForm.IMGPATH + styleInfo.BgImage.Path); if (styleInfo.BgImageClick != null && YU.stringHasText(styleInfo.BgImageClick.Path)) { styleInfo.BgImageClick.ImageLayout = ImageLayout.Stretch; if (YU.stringHasText(styleInfo.BgImageClick.Layout)) { if (Enum.TryParse(styleInfo.BgImageClick.Layout, out ImageLayout layout)) { styleInfo.BgImageClick.ImageLayout = layout; } } MouseDown += YobaButtonAbs_MouseDownBGChange; MouseUp += YobaButtonAbs_MouseUpBGChange; } if (styleInfo.BgImageHover != null && YU.stringHasText(styleInfo.BgImageHover.Path)) { styleInfo.BgImageHover.ImageLayout = ImageLayout.Stretch; if (YU.stringHasText(styleInfo.BgImageHover.Layout)) { if (Enum.TryParse(styleInfo.BgImageHover.Layout, out ImageLayout layout)) { styleInfo.BgImageHover.ImageLayout = layout; } } MouseEnter += YobaButtonAbs_MouseHoverBGChange; MouseLeave += YobaButtonAbs_MouseLeaveBGChange; } } }
public void InitCurrentVersion(string curVer) { ModConfigurationInfo = LauncherConfig.InstalledMods.Find(x => x.Name.Equals(Name)); CurrentVersionData = null; CurrentVersionFiles = new List <FileInfo>(); if (YU.stringHasText(curVer)) { if (GameVersions.ContainsKey(curVer)) { CurrentVersionData = GameVersions[curVer]; } } if (CurrentVersionData is null) { if (GameVersions.ContainsKey("DEFAULT")) { CurrentVersionData = GameVersions["DEFAULT"]; } else if (GameVersions.ContainsKey("OTHER")) { CurrentVersionData = GameVersions["OTHER"]; } } if (CurrentVersionData is null) { CurrentVersionFiles = null; } else { foreach (FileGroup fileGroup in CurrentVersionData.FileGroups) { if (fileGroup.Files != null) { CurrentVersionFiles.AddRange(fileGroup.Files); } } if (CurrentVersionData.Files != null) { CurrentVersionFiles.AddRange(CurrentVersionData.Files); } if (CurrentVersionFiles.Count > 0) { CurrentVersionFiles[CurrentVersionFiles.Count - 1].LastFileOfMod = this; } else { CurrentVersionFiles = null; } } if (ModConfigurationInfo != null) { if (CurrentVersionFiles is null) { if (ModConfigurationInfo.Active) { DisableOld(); } else { ModConfigurationInfo = null; } } else if (ModConfigurationInfo.Active) { foreach (string file in ModConfigurationInfo.FileList) { if (CurrentVersionFiles.FindIndex(x => x.Path.Equals(file)) < 0) { Program.LoncherSettings.zzModFilesToDelete.Add(file); //File.Delete(Program.GamePath + file); ModConfigurationInfo.Altered = true; } else { Program.LoncherSettings.zzModFilesInUse.Add(file); } } if (ModConfigurationInfo.Altered) { ModConfigurationInfo.FileList = new List <string>(); foreach (FileInfo fi in CurrentVersionFiles) { ModConfigurationInfo.FileList.Add(fi.Path); } } } } }
public Dictionary <string, GameVersion> PrepareGameVersions(List <GameVersion> rawGameVersions) { Dictionary <string, GameVersion> resultingGameVersions = new Dictionary <string, GameVersion>(); foreach (GameVersion gv in rawGameVersions) { string key = YU.stringHasText(gv.ExeVersion) ? gv.ExeVersion : "DEFAULT"; if (resultingGameVersions.ContainsKey(key)) { throw new Exception(string.Format(Locale.Get("MultipleFileBlocksForSingleGameVersion"), key)); } resultingGameVersions.Add(key, gv); } List <string> gvkeys = resultingGameVersions.Keys.ToList(); string[] anyKeys = new string[] { "ANY", "=", "DEFAULT" }; gvkeys.RemoveAll(s => anyKeys.Contains(s)); if (gvkeys.Count == 0) { if (!resultingGameVersions.ContainsKey("DEFAULT")) { resultingGameVersions.Add("DEFAULT", new GameVersion()); } GameVersion singleGV = resultingGameVersions["DEFAULT"]; foreach (string anyKey in anyKeys) { if (resultingGameVersions.ContainsKey(anyKey)) { GameVersion versionToMerge = resultingGameVersions[anyKey]; singleGV.FileGroups.AddRange(versionToMerge.FileGroups); singleGV.Files.AddRange(versionToMerge.Files); resultingGameVersions.Remove(anyKey); } } } else { foreach (string anyKey in anyKeys) { if (resultingGameVersions.ContainsKey(anyKey)) { GameVersion versionToMerge = resultingGameVersions[anyKey]; foreach (string gvkey in gvkeys) { GameVersion targetVersion = resultingGameVersions[gvkey]; foreach (FileGroup fg in versionToMerge.FileGroups) { FileGroup targetGroup = targetVersion.FileGroups.Find(x => x.Name == fg.Name); if (targetGroup is null) { targetGroup = FileGroup.CopyOf(fg); targetVersion.FileGroups.Add(targetGroup); } else { targetGroup.Files.AddRange(fg.Files); } } targetVersion.Files.AddRange(versionToMerge.Files); } resultingGameVersions.Remove(anyKey); } } } foreach (string gvkey in gvkeys) { GameVersion gv = resultingGameVersions[gvkey]; gv.FileGroups.Sort(); } return(resultingGameVersions); }