Ejemplo n.º 1
0
 private void PreloaderForm_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.F1)
     {
         YU.ShowHelpDialog();
     }
 }
Ejemplo n.º 2
0
        public PreloaderForm(MainForm oldMainForm)
        {
            InitializeComponent();
            oldMainForm_ = oldMainForm;
            this.BackgroundImageLayout = ImageLayout.Stretch;

            if (File.Exists(BG_FILE))
            {
                try {
                    this.BackgroundImage = YU.readBitmap(BG_FILE);
                }
                catch {
                    loadingLabelError.Text = Locale.Get("CannotSetBackground");
                }
            }
            if (File.Exists(ICON_FILE))
            {
                try {
                    Bitmap bm = YU.readBitmap(ICON_FILE);
                    if (bm != null)
                    {
                        Icon = Icon.FromHandle(bm.GetHicon());
                    }
                }
                catch {
                    loadingLabelError.Text = Locale.Get("CannotSetIcon");
                }
            }
            wc_ = new WebClient {
                Encoding = Encoding.UTF8
            };
            Text = Locale.Get("PreloaderTitle");
            loadingLabel.Text = string.Format(Locale.Get("LoncherLoading"), Program.LoncherName);
            labelAbout.Text   = Locale.Get("PressF1About");
        }
Ejemplo n.º 3
0
 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();
             }
         }
     }
 }
Ejemplo n.º 4
0
        private void launch()
        {
            string args = "/C \"" + ThePath + Program.LoncherSettings.ExeName + "\"";

            if (LauncherConfig.LaunchFromGalaxy)
            {
                args = string.Format("/command=runGame /gameId={1} /path=\"{0}\"", ThePath, Program.LoncherSettings.GogID);
                Process.Start(new ProcessStartInfo {
                    Arguments = args, FileName = LauncherConfig.GalaxyDir
                });
            }
            else
            {
                if (ThePath.Contains("steamapps"))
                {
                    args = "/C explorer steam://run/" + Program.LoncherSettings.SteamID;
                }
                Process.Start(new ProcessStartInfo {
                    Arguments = args, FileName = "cmd", WindowStyle = ProcessWindowStyle.Hidden
                });
            }
            YU.Log(args);
            launchGameButton.Enabled = false;
            System.Threading.Thread.Sleep(1800);
            if (LauncherConfig.CloseOnLaunch)
            {
                Application.Exit();
            }
            else
            {
                launchGameButton.Enabled = true;
            }
        }
Ejemplo n.º 5
0
 private bool assertOfflineFile(FileInfo fi, string dir, string targetPath)
 {
     if (fi != null && YU.stringHasText(fi.Path) && File.Exists(targetPath))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
        public override void ApplyUIStyles(UIElement styleInfo)
        {
            base.ApplyUIStyles(styleInfo);

            YU.setFont(this, styleInfo.Font, styleInfo.FontSize);
            if (styleInfo.CustomStyle)
            {
                BackColor = YU.colorFromString(styleInfo.BgColor, BtnColors.Back);
                FlatAppearance.BorderSize         = styleInfo.BorderSize > -1 ? styleInfo.BorderSize : 0;
                FlatAppearance.MouseOverBackColor = YU.colorFromString(styleInfo.BgColorHover, BtnColors.MouseOver);
                FlatAppearance.MouseDownBackColor = YU.colorFromString(styleInfo.BgColorDown, BtnColors.MouseDown);
            }
        }
Ejemplo n.º 8
0
 private void YobaButtonAbs_MouseUpBGChange(object sender, EventArgs e)
 {
     if (MouseHoverState)
     {
         BackgroundImageLayout = StyleInfo.BgImageHover.ImageLayout;
         BackgroundImage       = YU.readBitmap(PreloaderForm.IMGPATH + StyleInfo.BgImageHover.Path);
     }
     else
     {
         BackgroundImageLayout = StyleInfo.BgImage.ImageLayout;
         BackgroundImage       = YU.readBitmap(PreloaderForm.IMGPATH + StyleInfo.BgImage.Path);
     }
 }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        private string getGogGameInstallPath()
        {
            string gogId = Program.LoncherSettings.GogID;

            if (gogId is null)
            {
                return(null);
            }
            string[] locations = new string[] {
                @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" + gogId + "_is1"
                , @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + gogId + "_is1"
            };
            return(YU.GetRegistryInstallPath(locations, true));
        }
Ejemplo n.º 11
0
        private string getSteamGameInstallPath()
        {
            string steamId = Program.LoncherSettings.SteamID;

            if (steamId is null)
            {
                return(null);
            }
            string[] locations = new string[] {
                @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Steam App " + steamId
                , @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App " + steamId
            };
            return(YU.GetRegistryInstallPath(locations, true));
        }
Ejemplo n.º 12
0
        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);
            }
        }
Ejemplo n.º 13
0
 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);
         }
     }
 }
Ejemplo n.º 14
0
        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)));
                    }
                }
            }
        }
Ejemplo n.º 15
0
        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);
            }
        }
Ejemplo n.º 16
0
		public GamePathSelectForm() {
			InitializeComponent();

			folderBrowserDialog = new CommonOpenFileDialog() {
				IsFolderPicker = true
			};

			int style = NativeWinAPI.GetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE);
			style |= NativeWinAPI.WS_EX_COMPOSITED;
			NativeWinAPI.SetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE, style);

			YU.assertLucida(textBox1);

			button1.Text = Locale.Get("Browse");
			button2.Text = Locale.Get("Proceed");
			label1.Text = Locale.Get("EnterThePath");
			Text = Locale.Get("GamePathSelectionTitle");

			closeButton.UpdateLocation();
		}
Ejemplo n.º 17
0
 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);
 }
Ejemplo n.º 18
0
 public static string GetGogGalaxyPath()
 {
     try {
         using (RegistryKey view64 = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64)) {
             using (RegistryKey clsid64 = view64.OpenSubKey(@"goggalaxy\shell\open\command")) {
                 if (clsid64 != null)
                 {
                     string installLoc = (string)clsid64.GetValue("");
                     if (installLoc != null && installLoc.Length > 1)
                     {
                         installLoc = installLoc.Substring(1, installLoc.IndexOf('"', 2) - 1);
                         if (installLoc.Length > 0)
                         {
                             YU.Log("GalaxyInstalloc: " + installLoc);
                             return(installLoc);
                         }
                     }
                 }
             }
         }
     }
     catch { }
     return(null);
 }
Ejemplo n.º 19
0
        public SettingsDialog(MainForm mainForm) : base(new Size(480, 460), new UIElement[] {
            new UIElement() {
                Caption  = Locale.Get("Cancel")
                , Result = DialogResult.Cancel
            }
            , new UIElement() {
                Caption  = Locale.Get("Apply")
                , Result = DialogResult.OK
            }
        })
        {
            mainForm_ = mainForm;
            Text      = Locale.Get("SettingsTitle");

            SuspendLayout();

            folderBrowserDialog = new CommonOpenFileDialog()
            {
                IsFolderPicker = true
            };

            ToolTip theToolTip = new ToolTip();

            theToolTip.AutoPopDelay = 10000;
            theToolTip.InitialDelay = 200;
            theToolTip.ReshowDelay  = 100;

            Label gamePathLabel = new Label();

            gamePathLabel.Text     = Locale.Get("SettingsGamePath");
            gamePathLabel.Font     = new Font("Tahoma", 12F, FontStyle.Regular, GraphicsUnit.Pixel, 204);
            gamePathLabel.Location = new Point(18, 22);
            gamePathLabel.Size     = new Size(444, 40);

            gamePath             = new TextBox();
            gamePath.Text        = Program.GamePath;
            gamePath.Font        = new Font("Lucida Sans Unicode", 12F, FontStyle.Regular, GraphicsUnit.Pixel, 204);
            gamePath.Location    = new Point(2, 4);
            gamePath.Size        = new Size(359, 20);
            gamePath.BackColor   = Color.FromArgb(32, 33, 34);
            gamePath.BorderStyle = BorderStyle.None;
            gamePath.ForeColor   = Color.White;
            YU.assertLucida(gamePath);

            YobaButton browseButton = new YobaButton();

            browseButton.Location = new Point(385, 44);
            browseButton.Name     = "browseButton";
            browseButton.Size     = new Size(75, 27);
            browseButton.Text     = Locale.Get("Browse");
            browseButton.UseVisualStyleBackColor = false;
            browseButton.Click += new System.EventHandler(browseButton_Click);

            Panel fieldBackground = new Panel();

            fieldBackground.BackColor   = Color.FromArgb(32, 33, 34);
            fieldBackground.BorderStyle = BorderStyle.FixedSingle;
            fieldBackground.Controls.Add(gamePath);
            fieldBackground.Location = new Point(20, 44);
            fieldBackground.Name     = "fieldBackground";
            fieldBackground.Size     = new Size(361, 27);

            launchViaGalaxy           = new CheckBox();
            launchViaGalaxy.Text      = Locale.Get("SettingsGogGalaxy");
            launchViaGalaxy.Font      = new Font("Tahoma", 12F, FontStyle.Regular, GraphicsUnit.Pixel, 204);
            launchViaGalaxy.Location  = new Point(20, 86);
            launchViaGalaxy.Size      = new Size(440, 24);
            launchViaGalaxy.Checked   = LauncherConfig.LaunchFromGalaxy;
            launchViaGalaxy.BackColor = Color.Transparent;
            launchViaGalaxy.Enabled   = LauncherConfig.GalaxyDir != null;

            offlineMode           = new CheckBox();
            offlineMode.Text      = Locale.Get("SettingsOfflineMode");
            offlineMode.Font      = new Font("Tahoma", 12F, FontStyle.Regular, GraphicsUnit.Pixel, 204);
            offlineMode.Location  = new Point(20, 119);
            offlineMode.Size      = new Size(440, 24);
            offlineMode.Checked   = LauncherConfig.StartOffline;
            offlineMode.BackColor = Color.Transparent;

            theToolTip.SetToolTip(offlineMode, Locale.Get("SettingsOfflineModeTooltip"));

            closeLauncherOnLaunch           = new CheckBox();
            closeLauncherOnLaunch.Text      = Locale.Get("SettingsCloseOnLaunch");
            closeLauncherOnLaunch.Font      = new Font("Tahoma", 12F, FontStyle.Regular, GraphicsUnit.Pixel, 204);
            closeLauncherOnLaunch.Location  = new Point(20, 152);
            closeLauncherOnLaunch.Size      = new Size(440, 24);
            closeLauncherOnLaunch.Checked   = LauncherConfig.CloseOnLaunch;
            closeLauncherOnLaunch.BackColor = Color.Transparent;

            Label openingPanelLabel = new Label();

            openingPanelLabel.Text     = Locale.Get("SettingsOpeningPanel");
            openingPanelLabel.Font     = new Font("Tahoma", 12F, FontStyle.Regular, GraphicsUnit.Pixel, 204);
            openingPanelLabel.Location = new Point(18, 187);
            openingPanelLabel.Size     = new Size(444, 40);

            openingPanelCB            = new YobaComboBox();
            openingPanelCB.Location   = new Point(20, 208);
            openingPanelCB.Name       = "openingPanel";
            openingPanelCB.Size       = new Size(440, 22);
            openingPanelCB.DataSource = new string[] {
                Locale.Get("SettingsOpeningPanelChangelog")
                , Locale.Get("SettingsOpeningPanelStatus")
                , Locale.Get("SettingsOpeningPanelLinks")
                //, Locale.Get("SettingsOpeningPanelMods")
            };

            /*openingPanelCB = new YobaButton();
             * openingPanelCB.Location = new Point(20, 141);
             * openingPanelCB.Name = "openingPanel";
             *
             * YobaButton opt1 = new YobaComboBox();
             * opt1.Location = new Point(20, 141);
             * Size = new Size(440, 28);
             *
             * Panel cbDD = new Panel();
             * cbDD.BackColor = Color.FromArgb(40, 40, 41);
             * cbDD.BorderStyle = BorderStyle.FixedSingle;
             * cbDD.Controls.Add(gamePath);
             * cbDD.Location = new Point(20, 141 + openingPanelCB.Height);
             * cbDD.Name = "cbDD";
             * cbDD.Size = new Size(361, openingPanelCB.Height * 3);
             */
            YobaButton makeBackupBtn = new YobaButton();

            makeBackupBtn.MouseClick += MakeBackupBtn_MouseClick;
            makeBackupBtn.Location    = new Point(20, 246);
            makeBackupBtn.Size        = new Size(240, 24);
            makeBackupBtn.Text        = Locale.Get("SettingsMakeBackup");

            YobaButton createShortcutBtn = new YobaButton();

            createShortcutBtn.MouseClick += CreateShortcutBtn_MouseClick;
            createShortcutBtn.Location    = new Point(20, 286);
            createShortcutBtn.Size        = new Size(240, 24);
            createShortcutBtn.Text        = Locale.Get("SettingsCreateShortcut");

            /*YobaButton uninstallRussifierBtn = new YobaButton();
             * createShortcutBtn.MouseClick += CreateShortcutBtn_MouseClick;
             * createShortcutBtn.Location = new Point(20, 366);
             * createShortcutBtn.Size = new Size(240, 24);
             * createShortcutBtn.Text = Locale.Get("SettingsUninstallMainProduct");
             *
             * YobaButton uninstallLoncherBtn = new YobaButton();
             * createShortcutBtn.MouseClick += CreateShortcutBtn_MouseClick;
             * createShortcutBtn.Location = new Point(20, 406);
             * createShortcutBtn.Size = new Size(240, 24);
             * createShortcutBtn.Text = Locale.Get("SettingsUninstallRussifier");*/

            gamePath.TabIndex              = 1;
            browseButton.TabIndex          = 2;
            launchViaGalaxy.TabIndex       = 3;
            offlineMode.TabIndex           = 4;
            closeLauncherOnLaunch.TabIndex = 5;

            openingPanelCB.TabIndex    = 10;
            makeBackupBtn.TabIndex     = 15;
            createShortcutBtn.TabIndex = 16;

            Controls.Add(fieldBackground);
            Controls.Add(browseButton);
            Controls.Add(launchViaGalaxy);
            Controls.Add(offlineMode);
            Controls.Add(closeLauncherOnLaunch);
            Controls.Add(openingPanelCB);
            Controls.Add(makeBackupBtn);
            Controls.Add(createShortcutBtn);

            Controls.Add(openingPanelLabel);
            Controls.Add(gamePathLabel);

            Load += new EventHandler((object o, EventArgs a) => {
                openingPanelCB.SelectedIndex = (int)LauncherConfig.StartPage;
            });
            ResumeLayout();
        }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            try {
                if (!Directory.Exists(LoncherDataPath))
                {
                    FirstRun = true;
                    Directory.CreateDirectory(LoncherDataPath);
                }
                try {
                    if (Resource1.BuildTargetOpts.Length > 0)
                    {
                        string[] build = Resource1.BuildTargetOpts.Replace("\r", "").Split('\n');
                        if (build.Length > 0)
                        {
                            ParseBuildData();
                        }
                        void ParseBuildData()
                        {
                            StringBuilder sb    = new StringBuilder();
                            int           i     = 0;
                            int           li    = 0;
                            int           stage = 0;

                            while (build.Length >= i)
                            {
                                if (build.Length == i || build[i] == "---========---")
                                {
                                    switch (stage)
                                    {
                                    case 0:
                                        _loncherName = sb.ToString();
                                        break;

                                    case 1:
                                        _buildVersion = sb.ToString();
                                        break;

                                    case 2:
                                        _about = sb.ToString();
                                        break;

                                    case 3:
                                        _disclaimer = sb.ToString();
                                        return;
                                    }
                                    sb.Clear();
                                    li = 0;
                                    stage++;
                                }
                                else
                                {
                                    if (li > 0)
                                    {
                                        sb.Append("\r\n");
                                    }
                                    sb.Append(build[i]);
                                    li++;
                                }
                                i++;
                            }
                        };
                    }
                }
                catch (Exception ex) {
                    MessageBox.Show("Invalid Build info:\r\n\r\n" + ex.StackTrace);
                }
                try {
                    string[] buildDate = Resource1.BuildDate.Split('T');
                    DateTime date      = DateTime.Parse(buildDate[0]);
                    _buildNumber = "" + (date.Year - 2000) + date.Month.ToString("D2") + date.Day.ToString("D2") + buildDate[1].Substring(0, 5).Replace(' ', '0').Remove(2, 1);
                }
                catch {
                    _buildNumber = Resource1.BuildDate.Split(',')[0];
                }
                for (int aii = 0; aii < args.Length; aii++)
                {
                    string arg = args[aii];
                    if (arg == "-oldhash")
                    {
                        aii++;
                        if (args.Length > aii && args[aii].Length == 32)
                        {
                            PreviousVersionHash = args[aii];
                            FirstRun            = true;
                        }
                        else
                        {
                            MessageBox.Show("Usage error: a string MD5 hash must follow the -oldhash key");
                        }
                    }
                }
                Locale.LoadCustomLoc(Resource1.locale_default.Replace("\r", "").Split('\n'));
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new PreloaderForm());
            }
            catch (Exception exee) {
                YU.Log(exee.Message + "\r\n" + exee.StackTrace);
            }
        }
Ejemplo n.º 21
0
 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);
                 }
             }
         }
     }
 }
Ejemplo n.º 22
0
        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);
        }
Ejemplo n.º 23
0
 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);
     }
 }
Ejemplo n.º 24
0
        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();
        }
Ejemplo n.º 25
0
 private void helpButton_Click(object sender, EventArgs e)
 {
     YU.ShowHelpDialog();
 }
Ejemplo n.º 26
0
        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;
                }
            }
        }
Ejemplo n.º 27
0
 private void YobaButtonAbs_MouseDownBGChange(object sender, EventArgs e)
 {
     BackgroundImageLayout = StyleInfo.BgImageClick.ImageLayout;
     BackgroundImage       = YU.readBitmap(PreloaderForm.IMGPATH + StyleInfo.BgImageClick.Path);
 }
Ejemplo n.º 28
0
        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;
                }
                }
            }
        }
Ejemplo n.º 29
0
        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);
            }
        }