예제 #1
0
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        public override void OnFirstUpdate()
        {
            ThreadScheduler.Run(() =>
            {
                MapsetImporter.ImportMapsetsInQueue();

                if (MapDatabaseCache.MapsToUpdate.Count != 0)
                {
                    MapDatabaseCache.ForceUpdateMaps();
                }

                if (QuaverSettingsDatabaseCache.OutdatedMaps.Count != 0)
                {
                    var view         = View as ImportingScreenView;
                    view.Header.Text = "Please wait. Calculating difficulties for maps.";
                    QuaverSettingsDatabaseCache.RecalculateDifficultiesForOutdatedMaps();;
                }

                OnImportCompletion();
            });

            base.OnFirstUpdate();
        }
예제 #2
0
        /// <summary>
        ///     Uploads the mapset to the server
        /// </summary>
        private void UploadMapset() => ThreadScheduler.Run(() =>
        {
            try
            {
                Logger.Important($"Starting to upload mapset...", LogType.Network);

                var path = MapManager.Selected.Value.Mapset.ExportToZip(false);
                Response = OnlineManager.Client.UploadMapset(path);
                Logger.Important($"Uploaded mapset with response: {Response}", LogType.Network);

                File.Delete(path);

                // ReSharper disable once SwitchStatementMissingSomeCases
                switch (Response.Code)
                {
                case MapsetSubmissionStatusCode.SuccessUpdated:
                case MapsetSubmissionStatusCode.SuccessUploaded:
                    // Get all files in the directory and delete them, so we can get the updated ones
                    foreach (var f in Directory.GetFiles($"{ConfigManager.SongDirectory.Value}/{MapManager.Selected.Value.Directory}", "*.qua"))
                    {
                        File.Delete(f);
                    }

                    using (var conn = new SQLiteConnection(MapDatabaseCache.DatabasePath))
                        MapManager.Selected.Value.Mapset.Maps.ForEach(x => conn.Delete(x));

                    foreach (var map in Response.Maps)
                    {
                        if (map == null)
                        {
                            continue;
                        }

                        var filePath = $"{ConfigManager.SongDirectory.Value}/{MapManager.Selected.Value.Directory}/{map.Id}.qua";

                        Logger.Important($"Commencing download for map: {map.Id}", LogType.Runtime);

                        try
                        {
                            OnlineManager.Client.DownloadMap(filePath, map.Id);
                            Logger.Important($"Successfully downloaded map: {map.Id}", LogType.Network);
                        }
                        catch (Exception)
                        {
                            continue;
                        }

                        MapDatabaseCache.MapsToUpdate.Add(Map.FromQua(Qua.Parse(filePath), filePath));

                        Thread.Sleep(1000);
                    }

                    DividerLine.Tint = Color.LimeGreen;
                    TopLine.Tint     = Color.LimeGreen;

                    MapDatabaseCache.ForceUpdateMaps();
                    break;

                default:
                    DividerLine.Tint = Color.Crimson;
                    TopLine.Tint     = Color.Crimson;
                    break;
                }

                Header.Text = StatusCodeMessages[Response.Code];
            }
            catch (Exception e)
            {
                Logger.Error(e, LogType.Network);
                DividerLine.Tint = Color.Crimson;
                TopLine.Tint     = Color.Crimson;

                Header.Text = "An unknown error has occurred while uploading. Please check your log files!";
            }
            finally
            {
                LoadingWheel.Visible = false;
                CreateCloseButton();

                if (Response != null && (Response.Code == MapsetSubmissionStatusCode.SuccessUpdated ||
                                         Response.Code == MapsetSubmissionStatusCode.SuccessUploaded))
                {
                    CloseButton.Border.Tint = Color.LimeGreen;
                    CloseButton.Text.Tint   = Color.LimeGreen;

                    CreateVisitMapsetPageButton();
                    VisitMapsetPageButton.X = -VisitMapsetPageButton.Width / 2f - 10;
                    CloseButton.X           = CloseButton.Width / 2f + 10;
                }
            }
        });