public ManifestUtils(ProgressUtils progressUtil, FilesystemUtils fileSystemUtil, Uri soundCloudUri, EnumUtil.DownloadMode downloadMode, int syncMethod)
 {
     ProgressUtil  = progressUtil;
     SyncMethod    = syncMethod;
     DownloadMode  = downloadMode;
     SoundCloudUri = soundCloudUri;
     ManifestName  = MakeManifestString(
         FilesystemUtils.CoerceValidFileName(new StringBuilder(soundCloudUri.Host + soundCloudUri.PathAndQuery), false), fileSystemUtil.FoldersPerArtist, downloadMode, syncMethod);
     FileSystemUtil = fileSystemUtil;
 }
        private void syncButton_Click(object sender, EventArgs e)
        {
            SaveSettingsToConfig(ConfigStateCurrentIndex);

            _dlMode = playlistRadio.Checked
            ? EnumUtil.DownloadMode.Playlist
            : userPlaylists.Checked ? EnumUtil.DownloadMode.UserPlaylists
            : favoritesRadio.Checked ? EnumUtil.DownloadMode.Favorites
            : artistRadio.Checked ? EnumUtil.DownloadMode.Artist : EnumUtil.DownloadMode.Track;
            if (!string.IsNullOrWhiteSpace(url.Text?.ToLower()) &&
                !string.IsNullOrWhiteSpace(directoryPath.Text?.ToLower()) &&
                !IsSyncButtonClicked)
            {
                IsSyncButtonClicked    = true;
                syncButton.Tag         = "STR_ABORT";
                syncButton.Text        = LanguageManager.Language[syncButton.Tag.ToString()];
                status.Tag             = "STR_MAIN_STATUS_CHECK";
                status.Text            = LanguageManager.Language[status.Tag.ToString()];
                progressUtil.Completed = false;

                progressBar.Value   = 0;
                progressBar.Maximum = 0;
                progressBar.Minimum = 0;
                TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal);

                Highqualitysong = chk_highquality.Checked;
                ConvertToMp3    = chk_convertToMp3.Checked;

                SyncMethod               = rbttn_oneWay.Checked ? 1 : 2;
                FoldersPerArtist         = chk_folderByArtist.Checked;
                ReplaceIllegalCharacters = chk_replaceIllegalCharacters.Checked;
                ExcludeAac               = chk_excl_m4a.Checked;
                ExcludeM4A               = chk_excl_m4a.Checked;
                CreatePlaylists          = chk_CreatePlaylists.Checked;
                ConcurrentDownloads      = (int)nudConcurrency.Value;
                MergePlaylists           = chk_MergePlaylists.Checked;

                Uri soundCloudUri;
                try
                {
                    soundCloudUri = new Uri(url?.Text?.ToLower());
                }
                catch (Exception)
                {
                    status.Tag             = "STR_MAIN_STATUS_INVALIDURL";
                    status.Text            = LanguageManager.Language[status.Tag.ToString()];
                    progressUtil.Completed = true;
                    InvokeSyncComplete();
                    return;
                }

                var           filesystemUtil = new FilesystemUtils(new DirectoryInfo(directoryPath?.Text?.ToLower()), trackRadio.Checked ? FormatForTag : FormatForName, FoldersPerArtist, ReplaceIllegalCharacters);
                var           manifestUtil   = new ManifestUtils(progressUtil, filesystemUtil, soundCloudUri, _dlMode, SyncMethod);
                var           playlistUtil   = new PlaylistUtils(manifestUtil);
                DownloadUtils downloadUtil   = new DownloadUtils(clientIdUtil, ExcludeM4A, ExcludeAac, ConvertToMp3, manifestUtil, Highqualitysong, ConcurrentDownloads);
                var           syncUtil       = new SyncUtils(CreatePlaylists, manifestUtil, downloadUtil, playlistUtil);
                if (_dlMode != EnumUtil.DownloadMode.Track)
                {
                    bool differentmanifest;
                    if (!manifestUtil.FindManifestAndBackup(out differentmanifest))
                    {
                        if (differentmanifest)
                        {
                            status.Tag             = "STR_MAIN_STATUS_DIFFMANY";
                            status.Text            = LanguageManager.Language[status.Tag.ToString()];
                            progressUtil.Completed = true;
                            InvokeSyncComplete();
                            return;
                        }
                    }
                }
                new Thread(() =>
                {
                    // perform progress updates
                    while (!progressUtil.Completed && !progressUtil.Exiting)
                    {
                        Thread.Sleep(500);
                        InvokeUpdateStatus();

                        this.Invoke((MethodInvoker)(() => lb_progressOfTracks.DataSource = progressUtil.GetTrackProgressValues()));
                        this.Invoke((MethodInvoker)(() => lb_progressOfTracks.Refresh()));

                        InvokeUpdateProgressBar();
                    }
                    if (!progressUtil.Exiting)
                    {
                        InvokeUpdateStatus();
                    }
                }).Start();

                new Thread(() =>
                {
                    try
                    {
                        var sync = new SoundcloudSync(syncUtil, MergePlaylists);
                        sync.Synchronize(url?.Text?.ToLower());
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"{ex.Message} { ExceptionHandlerUtils.GetInnerExceptionMessages(ex)}", LanguageManager.Language["STR_ERR"]);
                    }
                    finally
                    {
                        progressUtil.Completed = true;
                        InvokeSyncComplete();
                    }
                }).Start();
            }
            else if (progressUtil.IsActive && IsSyncButtonClicked)
            {
                progressUtil.IsActive = false;
                syncButton.Enabled    = false;
            }
            else if (!IsSyncButtonClicked && string.IsNullOrWhiteSpace(url.Text))
            {
                status.Tag  = "STR_MAIN_STATUS_NULLURL";
                status.Text = LanguageManager.Language[status.Tag.ToString()];
            }
            else if (!IsSyncButtonClicked && string.IsNullOrWhiteSpace(directoryPath.Text))
            {
                status.Tag  = "STR_MAIN_STATUS_NULLDIR";
                status.Text = LanguageManager.Language[status.Tag.ToString()];
            }
        }
 public static string MakeManifestString(string validManifestFilename, bool foldersPerArtist, EnumUtil.DownloadMode dlMode, int syncMethod)
 {
     return(".MNFST=" + validManifestFilename + ",FPA=" + foldersPerArtist + ",DM=" + dlMode + ",SM=" + syncMethod + ".json");
 }