Esempio n. 1
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;
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
 }
Esempio n. 4
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;
                }
                }
            }
        }
Esempio n. 5
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);
            }
        }