public OsuDirectDownload(int setId, string filename, string title = null, bool noVideo = false, int filesize = 0) : this()
        {
            this.filename = filename;
            this.filesize = filesize;
            this.title    = title;

            Directory.CreateDirectory(DownloadsFolder);

            localFilename = Path.GetFileName(filename);
            string destination = Path.Combine(DownloadsFolder, localFilename);

            try
            {
                File.Delete(destination);
            }
            catch
            {
                return;
            }

            string urlRoot = !noVideo ? Urls.BEATMAP_SET_DOWNLOAD : Urls.BEATMAP_SET_DOWNLOAD_NO_VIDEO;

            request                   = new pFileWebRequest(destination, string.Format(urlRoot + "?u={1}&h={2}", setId, ConfigManager.sUsername, ConfigManager.sPassword));
            request.Started          += req_onStart;
            request.Finished         += req_onFinish;
            request.DownloadProgress += req_onUpdate;
        }
Example #2
0
        internal static void Initialize()
        {
            if (Initializing)
            {
                return;
            }
            Initializing = true;

            if (!File.Exists(filterPath) || (DateTime.Now - File.GetLastWriteTime(filterPath)).TotalDays > 7)
            {
                pFileWebRequest fnr = new pFileWebRequest(filterPath, General.WEB_ROOT + "/release/filter.txt");
                fnr.Finished += delegate { LoadData(); };
                fnr.Perform();
                return;
            }

            LoadData();
        }
Example #3
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
            {
            }
        }
Example #4
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;
            }
        }
        private void req_onFinish(pWebRequest r, Exception e)
        {
            pFileWebRequest fnr = r as pFileWebRequest;

            try
            {
                File.Delete(Path.Combine(BeatmapManager.SongsDirectory, localFilename));
            }
            catch
            {
                NotificationManager.ShowMessage("osu!Direct download failed because the file already exists in your songs folder and is not writeable.");
            }

            bool succeeded = e == null;

            try
            {
                if (succeeded && File.Exists(fnr.Filename))
                {
                    succeeded &= new FileInfo(fnr.Filename).Length > 100;

                    if (!succeeded)
                    {
                        string text = File.ReadAllText(fnr.Filename);
                        File.Delete(fnr.Filename);

                        if (text.StartsWith(@"ERROR:"))
                        {
                            switch (text.Replace(@"ERROR:", @"").Trim())
                            {
                            case @"DOWNLOAD_NOT_AVAILABLE":
                                NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.OsuDirect_DownloadNotAvailable), Color.DarkRed, 4000, delegate
                                {
                                    GameBase.ProcessStart(string.Format(Urls.BEATMAP_SET_DOWNLOAD, beatmap.setId));
                                });
                                break;
                            }

                            return;
                        }
                    }

                    string ext = Path.GetExtension(filename).ToLower();

                    string songs_fullpath = Path.GetFullPath(BeatmapManager.SongsDirectory);
                    int    charsOver      = songs_fullpath.Length + filename.Length - GeneralHelper.MAX_PATH_LENGTH;

                    if (charsOver > 0)
                    {
                        if (charsOver < filename.Length - (ext.Length + 1) - 1)
                        {
                            filename = filename.Substring(0, filename.Length - charsOver - (ext.Length + 1)) + ext;
                        }
                        else
                        {
                            succeeded = false;
                        }
                    }

                    if (succeeded)
                    {
                        if (!Player.Playing || ConfigManager.sPopupDuringGameplay.Value)
                        {
                            AudioEngine.PlaySample(@"match-confirm");
                        }
                        File.Move(fnr.Filename, Path.Combine(BeatmapManager.SongsDirectory, localFilename));
                    }
                    else
                    {
                        NotificationManager.ShowMessage("osu!direct download failed. Please check your connection and try again!");
                        File.Delete(fnr.Filename);
                    }
                }
            }
            finally
            {
                OnFinish(succeeded);
            }
        }