Beispiel #1
0
        public void Start()
        {
            LoadingTimer.Start();
            new Action(() =>
            {
                CurrentFormState = FormState.Running;
                if (MovieMode)
                {
                    foreach (var Movie in Movies.OrderBy(x => x.Name))
                    {
                        try
                        {
                            foreach (var Sub in Movie.Subs)
                            {
                                try
                                {
                                    if (!File.Exists(Sub.Destination))
                                    {
                                        File.Move(Sub.FilePath, Sub.Destination);
                                    }
                                    SubsDone++;
                                    UpdateNumbers(Sub.ToString());
                                    Thread.Sleep(100);
                                }
                                catch (Exception ex)
                                { IncreaseError(ex); }
                            }
                            if (!File.Exists(Movie.Destination))
                            {
                                File.Move(Movie.FilePath, Movie.Destination);
                            }
                            MoviesDone++;
                            UpdateNumbers(Movie.ToString());
                            Thread.Sleep(100);
                        }
                        catch (Exception ex)
                        { IncreaseError(ex); }
                    }
                }
                else
                {
                    foreach (var Season in Seasons.OrderBy(x => x.SeasonNumber))
                    {
                        foreach (var Episode in Season.Episodes.OrderBy(x => x.EpisodeNumber))
                        {
                            try
                            {
                                foreach (var Sub in Episode.Subs)
                                {
                                    try
                                    {
                                        if (!File.Exists(Sub.Destination))
                                        {
                                            File.Move(Sub.FilePath, Sub.Destination);
                                        }
                                        SubsDone++;
                                        UpdateNumbers(Sub.ToString());
                                        Thread.Sleep(100);
                                    }
                                    catch (Exception ex)
                                    { IncreaseError(ex); }
                                }
                                if (!File.Exists(Episode.Destination))
                                {
                                    File.Move(Episode.FilePath, Episode.Destination);
                                }
                                EpisodesDone++;
                                UpdateNumbers(Episode.ToString());
                                Thread.Sleep(100);
                            }
                            catch (Exception ex)
                            { IncreaseError(ex); }
                        }
                        SeasonsDone++;
                        UpdateNumbers(Season.ToString());
                    }
                }
                Invoke(new Action(() => { L_CurrentWork.Text = "Cleaning Up..."; }));

                if (O_CleanFolders)
                {
                    try
                    {
                        foreach (var item in JunkFiles)
                        {
                            try
                            {
                                var file        = new FileInfo(item);
                                file.Attributes = file.Attributes & ~FileAttributes.ReadOnly;
                                file.Delete();
                            }
                            catch (Exception ex) { IncreaseError(ex); }
                        }


                        foreach (var item in Directory.GetDirectories(FolderPath, "*", SearchOption.AllDirectories))
                        {
                            if (DirectoryIsEmpty(item))
                            {
                                try
                                {
                                    var dir        = new DirectoryInfo(item);
                                    dir.Attributes = dir.Attributes & ~FileAttributes.ReadOnly;
                                    foreach (var fil in Directory.GetFiles(item, "*", SearchOption.AllDirectories))
                                    {
                                        var file        = new FileInfo(fil);
                                        file.Attributes = file.Attributes & ~FileAttributes.ReadOnly;
                                        file.Delete();
                                    }
                                    dir.Delete();
                                }
                                catch (Exception ex) { IncreaseError(ex); }
                            }
                        }

                        if (!MovieMode && !Directory.Exists(Directory.GetParent(FolderPath).FullName + "\\" + SeriesName))
                        {
                            Directory.Move(FolderPath, Directory.GetParent(FolderPath).FullName + "\\" + SeriesName);
                        }
                    }
                    catch (Exception ex) { IncreaseError(ex); }
                }

                Invoke(new Action(() =>
                {
                    CurrentFormState = FormState.Normal;
                    B_Done.Show();
                    L_CurrentWork.Text = "";
                    if (L_Errors.Text != "0")
                    {
                        progressBar.Value         = progressBar.Maximum;
                        progressBar.Text          = "100";
                        progressBar.ProgressColor = Color.FromArgb(242, 60, 53);
                        LoadingTimer.Dispose();
                        LoadingTimer = null;
                    }
                    if (ErrorList != "")
                    {
#if DEBUG
                        File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Renamer Log.txt", ErrorList);
#else
                        if (MessageBox.Show("Errors Occured, would you like to save the Error Log?", "Save Error Log?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Renamer Log.txt", ErrorList);
                        }
#endif
                    }
                }));
            }).RunInBackground(1250);
        }