Пример #1
0
        void init()
        {
            try
            {
                SplashScreen.CloseAll();

                BringToFrontEx();

                bool hasLanguage = LocalisationManager.IsInitialised;

                if (!hasLanguage)
                {
                    Invoke(delegate
                    {
                        LocalisationManager.SetLanguage(null, false, delegate { hasLanguage = true; }, osu.Properties.Resources.en);
                    });

                    int timeout = 20000;
                    while (!hasLanguage && (timeout -= 100) > 0)
                    {
                        setText(@"Downloading localisation...", true);
                        Thread.Sleep(100);
                    }
                }

                while (true)
                {
                    try
                    {
                        instance = new SingleInstance(OsuMain.ClientGuid, 500);
                    }
                    catch (TooManyInstancesException)
                    {
                        if (OsuMain.IsWine)
                        {
                            break;
                        }

                        setText(LocalisationManager.GetString(OsuString.Maintenance_OsuIsAlreadyRunning), true);
                        Thread.Sleep(100);
                        continue;
                    }

                    break;
                }

                if (!DotNetFramework.CheckInstalled(FrameworkVersion.dotnet4))
                {
                    Process installProcess = null;

                    string dotNetInstallFilename = Environment.OSVersion.Version.Major < 6 ? @"dotNetFx40_Full_setup.exe" : @"NDP452-KB2901954-Web.exe";

                    setText(LocalisationManager.GetString(OsuString.Maintenance_DotNetInstall), true);
                    pFileWebRequest fnr = new pFileWebRequest(dotNetInstallFilename, @"http://m1.ppy.sh/r/" + dotNetInstallFilename);
                    fnr.DownloadProgress += delegate(pWebRequest sender, long current, long total)
                    {
                        setProgress((float)current / total * 100, OsuString.Maintenance_DotNetInstall);
                    };

                    try
                    {
                        fnr.BlockingPerform();
                        installProcess = Process.Start(dotNetInstallFilename, @"/passive /promptrestart");

                        while (installProcess != null && !installProcess.HasExited)
                        {
                            setText(LocalisationManager.GetString(OsuString.Maintenance_WaitingForDotNetComplete), true);
                            setProgress();
                            Thread.Sleep(500);
                        }
                    }
                    catch
                    {
                    }

                    GeneralHelper.FileDelete(dotNetInstallFilename);

                    label.Click += manualDotNetInstall;
                    while (!DotNetFramework.CheckInstalled(FrameworkVersion.dotnet4, false))
                    {
                        setText(LocalisationManager.GetString(OsuString.Maintenance_DotNetFailed), true);
                        setProgress();
                        Thread.Sleep(500);
                    }
                    label.Click -= manualDotNetInstall;
                }

                setText();
                setProgress();
            }
            catch
            {
            }
        }
Пример #2
0
        internal void Perform(bool doPatching = false)
        {
            isRunning        = true;
            progress         = 0;
            downloaded_bytes = 0;
            isPatching       = false;

            if (doPatching && url_patch == null)
            {
                throw new Exception(@"patch not available for this file!");
            }

            string localPath = CommonUpdater.STAGING_FOLDER + "/" + filename + (doPatching ? "_patch" : @".zip");

            netRequest = new pFileWebRequest(localPath, doPatching ? url_patch : (url_full + @".zip"));
            netRequest.DownloadProgress += delegate(pWebRequest sender, long current, long total)
            {
                progress         = (float)current / total * (doPatching ? 50 : 100);
                downloaded_bytes = (int)current;
                filesize         = (int)total;
            };

            try
            {
                netRequest.BlockingPerform();
                if (netRequest.Aborted)
                {
                    isRunning = false;
                }
                else if (!File.Exists(localPath))
                {
                    throw new Exception(@"couldn't find downloaded file (" + localPath + ")");
                }
            }
            catch (ThreadAbortException)
            {
                isRunning = false;
                return;
            }

            if (netRequest.Filename.EndsWith(@".zip"))
            {
                FastZip fz = new FastZip();
                fz.ExtractZip(localPath, CommonUpdater.STAGING_FOLDER, @".*");
                GeneralHelper.FileDelete(localPath);
            }

            if (doPatching)
            {
                string beforePatch = CommonUpdater.STAGING_FOLDER + @"/" + filename;
                string afterPatch  = CommonUpdater.STAGING_FOLDER + @"/" + filename + @"_patched";

                try
                {
                    isPatching = true;
                    BSPatcher patcher = new BSPatcher();
                    patcher.OnProgress += delegate(object sender, long current, long total) { progress = 50 + (float)current / total * 50; };
                    patcher.Patch(beforePatch, afterPatch, localPath);
                }
                finally
                {
                    GeneralHelper.FileDelete(localPath);
                    GeneralHelper.FileDelete(beforePatch);
                    if (File.Exists(afterPatch))
                    {
                        GeneralHelper.FileMove(afterPatch, beforePatch);
                    }
                    isPatching = false;
                }

                isRunning = false;
            }
        }