コード例 #1
0
ファイル: ErrorMessage.cs プロジェクト: Athlon007/msc-ogg
        private void BtnMoreDetail_Click(object sender, EventArgs e)
        {
            isExtended        ^= true;
            this.Size          = new Size(this.Size.Width, isExtended ? extendedHeight : defaultHeight);
            btnMoreDetail.Text = isExtended ? (char.ConvertFromUtf32(0x2191) + " " + Localisation.Get("Hide More Info"))
                : (char.ConvertFromUtf32(0x2193) + " " + Localisation.Get("Show More Info"));
            string file = File.ReadAllText($"LOG\\{FileName}.txt");

            file           = file.Replace("\n", Environment.NewLine);
            logOutput.Text = file;
        }
コード例 #2
0
ファイル: QuickConvert.cs プロジェクト: Athlon007/msc-ogg
 private void QuickConvert_KeyDown(object sender, KeyEventArgs e)
 {
     // Refresh the localization (translator mode)
     if (Settings.TranslatorMode)
     {
         if (e.KeyCode == Keys.F5)
         {
             Localisation.LoadLocaleFile();
             Localise();
         }
     }
 }
コード例 #3
0
ファイル: Player.cs プロジェクト: Athlon007/msc-ogg
        /// <summary>
        /// Randomizes songs order in folder.
        /// </summary>
        /// <param name="folder">Folder in which files will be shuffled</param>
        public static void Shuffle(string folder)
        {
            if (Utilities.IsToolBusy())
            {
                MessageBox.Show(Localisation.Get("Program is busy."), Localisation.Get("Stop"), MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            IsBusy = true;
            Stop();

            if (Form1.instance != null)
            {
                Form1.instance.Log(Localisation.Get("Shuffling!"));
            }

            try
            {
                // Collecting all files into FileInfo list
                DirectoryInfo   di    = new DirectoryInfo($"{Settings.GamePath}\\{folder}");
                List <FileInfo> files = new List <FileInfo>(di.GetFiles("track*.ogg"));

                // Renaming files to temporary name
                for (int i = 0; i < files.Count; i++)
                {
                    string file = $"{Settings.GamePath}\\{folder}\\{files[i].Name.Replace(".ogg", "")}"; // path + file name without extension
                    File.Move($"{file}.ogg", $"{file}.ogg.temp");
                    MetaData.ChangeFile(files[i].Name.Replace(".ogg", ""), $"{files[i].Name.Replace(".ogg", "")}_temp");
                }

                // Randomizing order of files list
                files = files.OrderBy(a => Guid.NewGuid()).ToList();

                // Now moving the files with temporary names to new name
                for (int i = 0; i < files.Count; i++)
                {
                    string file = $"{Settings.GamePath}\\{folder}\\{files[i].Name.Replace(".ogg", "")}"; // path + file name without extension
                    File.Move($"{file}.ogg.temp", $"{Settings.GamePath}\\{folder}\\track{i + 1}.ogg");
                    MetaData.ChangeFile($"{files[i].Name.Replace(".ogg", "")}_temp", $"track{i + 1}");
                }

                MetaData.SortDatabase();
            }
            catch (Exception ex)
            {
                ErrorMessage err = new ErrorMessage(ex);
                err.ShowDialog();
            }
            finally
            {
                IsBusy = false;
            }
        }
コード例 #4
0
        private void BtnDelHis_Click(object sender, EventArgs e)
        {
            DialogResult dl = MessageBox.Show(Localisation.Get("Are you sure you want to remove entire history?"),
                                              Localisation.Get("Question"),
                                              MessageBoxButtons.YesNo,
                                              MessageBoxIcon.Question);

            if (dl == DialogResult.Yes && File.Exists("history.txt"))
            {
                File.Delete("history.txt");
            }
        }
コード例 #5
0
        private void BtnDelLogs_Click(object sender, EventArgs e)
        {
            DialogResult dl = MessageBox.Show(Localisation.Get("Are you sure you want to delete all logs?"),
                                              Localisation.Get("Question"),
                                              MessageBoxButtons.YesNo,
                                              MessageBoxIcon.Question);

            if (dl == DialogResult.Yes && Directory.Exists("LOG"))
            {
                Directory.Delete("LOG", true);
            }
        }
コード例 #6
0
        private void BtnCheckUpdate_Click(object sender, EventArgs e)
        {
            // Force download and install update
            if (ModifierKeys.HasFlag(Keys.Shift))
            {
                Form1.instance.Log(Localisation.Get("\nForcing the update..."));
                Updates.DownloadUpdate(Settings.Preview);
                return;
            }

            Updates.StartUpdateCheck();
        }
コード例 #7
0
        private void ChkNoMetafiles_Click(object sender, EventArgs e)
        {
            if (!Settings.DisableMetaFiles)
            {
                DialogResult dl = MessageBox.Show(
                    Localisation.Get("Disabling metafiles will result in MSC Music Manager using file names, instead of saved song names.\n" +
                                     "Are you sure you want to continue?"),
                    Localisation.Get("Question"),
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Stop);

                if (dl != DialogResult.Yes)
                {
                    chkNoMetafiles.Checked ^= true;
                    return;
                }
            }

            Player.Stop();
            Settings.DisableMetaFiles ^= true;

            if (Settings.DisableMetaFiles)
            {
                DialogResult removeMeta = MessageBox.Show(
                    Localisation.Get("Would you like to remove ALL meta files?"),
                    Localisation.Get("Question"),
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);

                if (removeMeta == DialogResult.Yes)
                {
                    MetaData.RemoveAll($"Radio");
                    MetaData.RemoveAll($"CD");
                }
            }
            else
            {
                DialogResult getMeta = MessageBox.Show(
                    Localisation.Get("Would you like the MSCMM to get song names directly from files now? " +
                                     "(It may take some time, depending on how many songs you have)"),
                    Localisation.Get("Question"),
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);

                if (getMeta == DialogResult.Yes)
                {
                    MetaData.GetMetaFromAllSongs($"Radio");
                    MetaData.GetMetaFromAllSongs($"CD");
                }
            }
            Form1.instance.UpdateSongList();
        }
コード例 #8
0
        private void ComboLang_SelectionChangeCommitted(object sender, EventArgs e)
        {
            // Ignore setting change, if the value selected is the same
            if (comboLang.Text == Settings.Language)
            {
                return;
            }

            Settings.Language = comboLang.Text;
            Localisation.LoadLocaleFile();
            Form1.instance.Localize();
            this.Localise();
        }
コード例 #9
0
        void Localise()
        {
            chkShortcut.Text         = Localisation.Get("Desktop shortcut");
            chkNoSteam.Text          = Localisation.Get("Start the game without Steam");
            label2.Text              = Localisation.Get("Language");
            chkAutoSort.Text         = Localisation.Get("Sort files after conversion");
            chkNoMetafiles.Text      = Localisation.Get("Don't save song names");
            chkAutoUpdates.Text      = Localisation.Get("Automatically look for updates");
            label1.Text              = Localisation.Get("Update Channel:");
            radOfficial.Text         = Localisation.Get("Official");
            radPreview.Text          = Localisation.Get("Preview");
            btnCheckUpdate.Text      = Localisation.Get("Check for Update");
            label3.Text              = Localisation.Get("Check for youtube-dl updates:");
            btnCheckYTDLUpdates.Text = Localisation.Get("Check for Update");
            chkCrashLog.Text         = Localisation.Get("Create logs after crash");
            chkHistory.Text          = Localisation.Get("Save usage into history");
            label4.Text              = Localisation.Get("History");
            btnOpenHistory.Text      = Localisation.Get("Open history");
            btnDelHis.Text           = Localisation.Get("Delete history");
            label5.Text              = Localisation.Get("Logs");
            btnOpenLog.Text          = Localisation.Get("Open last log");
            btLogFolder.Text         = Localisation.Get("Open Log Folder");
            btnDelLogs.Text          = Localisation.Get("Delete all logs");
            labNotice.Text           = Localisation.Get("Notice: not a single log or any info is sent from your computer." +
                                                        "\nEverything that is being logged is saved on Your computer.");

            tabGeneral.Text              = Localisation.Get("General");
            tabFiles.Text                = Localisation.Get("Files");
            tabUpdates.Text              = Localisation.Get("Updates");
            tabLogging.Text              = Localisation.Get("Logging & Privacy");
            this.Text                    = Localisation.Get("Settings");
            chkShowFfmpegOutput.Text     = Localisation.Get("Show ffmpeg output");
            chkIgnoreLimits.Text         = Localisation.Get("Ignore limitation of songs in folder");
            labAudacity.Text             = Localisation.Get("Audacity Executable:");
            label6.Text                  = Localisation.Get("Music Download Quality:");
            radQualityBest.Text          = Localisation.Get("Best");
            radQualityAverage.Text       = Localisation.Get("Average");
            radQualityCompressed.Text    = Localisation.Get("Compressed");
            btnChangelogHistory.Text     = Localisation.Get("View Changelog History");
            chkRecommendedFrequency.Text = Localisation.Get("Set the music frequency to recomended 22050 Hz frequency");
            chkMono.Text                 = Localisation.Get("Convert song to mono channel");
            label7.Text                  = Localisation.Get("Conversion:");
            labTranslator.Text           = Localisation.Get("Translation Author:\n{0}", Localisation.TranslationAuthor);
            chkTranslatorMode.Text       = Localisation.Get("Translator Mode");
            label8.Text                  = Localisation.Get("Shuffle and Play Shortcut:");
            btnCreateCustomShortcut.Text = Localisation.Get("Create");
            label9.Text                  = Localisation.Get("Creates a custom game shortcut that first starts MSCMM\n" +
                                                            "and shuffles all songs, then starts the game.");
            chkCreateLocaleErrorLogs.Text = Localisation.Get("Create locale error logs");
        }
コード例 #10
0
        /// <summary>
        /// Moves the file to "Recycle Bin" folder inside of folder param.
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="files"></param>
        public static void Remove(string folder, string[] files)
        {
            if (Utilities.IsToolBusy())
            {
                Form1.instance.Log(Localisation.Get("Program is busy."));
                return;
            }

            try
            {
                Player.Stop();

                foreach (string file in files)
                {
                    string filePath = $"{Settings.GamePath}\\{folder}\\{file}.ogg";
                    if (File.Exists(filePath))
                    {
                        if (!Directory.Exists($"{Settings.GamePath}\\Recycle Bin"))
                        {
                            Directory.CreateDirectory($"{Settings.GamePath}\\Recycle Bin");
                        }

                        while (!Utilities.IsFileReady(filePath))
                        {
                        }

                        string name = MetaData.GetName(file.Split('.')[0]);
                        File.Move(filePath, $"{Settings.GamePath}\\Recycle Bin\\{name}.ogg");
                        MetaData.Remove(file);

                        Logs.History(Localisation.Get("Moved '{0}' ({1}) from {2} to recycle bin", name, file, folder));
                        Form1.instance.Log(Localisation.Get("Moved '{0}' ({1}) from {2} to recycle bin", name, file, folder));
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage err = new ErrorMessage(ex);
                err.ShowDialog();
            }
            finally
            {
                if (Settings.AutoSort)
                {
                    Player.Sort(folder);
                }

                Form1.instance.UpdateSongList();
            }
        }
コード例 #11
0
        /// <summary>
        /// Restores files from the recycle bin
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="files"></param>
        public static void Restore(string folder, string[] files)
        {
            if (Utilities.IsToolBusy())
            {
                Form1.instance.Log(Localisation.Get("Program is busy."));
                return;
            }

            if (!Directory.Exists($"{Settings.GamePath}\\Recycle Bin"))
            {
                return;
            }

            try
            {
                foreach (string file in files)
                {
                    string filePath = $"{Settings.GamePath}\\Recycle Bin\\{file}.ogg";
                    if (File.Exists(filePath))
                    {
                        while (!Utilities.IsFileReady(filePath))
                        {
                        }

                        string newFileName = $"track{Utilities.GetNewFileNumber(folder)}";
                        File.Move(filePath, $"{Settings.GamePath}\\{folder}\\{newFileName}.ogg");
                        MetaData.AddOrEdit(newFileName, file);

                        Logs.History(Localisation.Get("Restored '{0}' from the recycle bin", file));
                        Form1.instance.Log(Localisation.Get("Restored '{0}' from the recycle bin", file));
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage err = new ErrorMessage(ex);
                err.ShowDialog();
            }
            finally
            {
                if (Settings.AutoSort)
                {
                    Player.Sort(folder);
                }

                Form1.instance.UpdateSongList();
            }
        }
コード例 #12
0
        /// <summary>
        /// Starts youtube-dl with -U parameter which makes it check for new updates directly from youtube-dl server
        /// </summary>
        /// <returns></returns>
        static async Task GetYoutubeDlUpdate()
        {
            IsYoutubeDlUpdating = true;
            Form1.instance.Log("\n" + Localisation.Get("Looking for youtube-dl updates..."));
            Process process = new Process();

            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.StartInfo.FileName    = "youtube-dl.exe";
            process.StartInfo.Arguments   = "-U";
            process.Start();
            await Task.Run(() => process.WaitForExit());

            Form1.instance.Log(Localisation.Get("youtube-dl is up-to-date!"));
            IsYoutubeDlUpdating          = false;
            Settings.LastYTDLUpdateCheck = DateTime.Now;
        }
コード例 #13
0
        /// <summary>
        /// Downloads ffmpeg and ffplay from MSCMM's Git repo
        /// </summary>
        /// <returns></returns>
        static async Task GetFFmpeg()
        {
            using (WebClient client = new WebClient())
            {
                client.DownloadProgressChanged += (s, e) =>
                {
                    Form1.instance.DownloadProgress.Invoke(new Action(() =>
                    {
                        Form1.instance.DownloadProgress.Visible = true;
                        Form1.instance.DownloadProgress.Value   = e.ProgressPercentage;
                    }));
                    return;
                };

                string link = (Settings.Preview ? preview : stable) + "Dependencies/ffpack.zip";

                try
                {
                    await Task.Run(() => client.DownloadFileAsync(new Uri(link), "ffpack.zip"));
                }
                catch
                {
                    MessageBox.Show(Localisation.Get("Looks like there was some kind of problem with downloading the FFmpeg pack. " +
                                                     "You'll be taken to the website from which you'll" +
                                                     " download the ffpack.zip. Unzip it into the root folder of MSCMM."));
                    Process.Start("https://gitlab.com/aathlon/msc-ogg/raw/ab9cb011a283f316d56a4ce11b32558887a6fe39/Dependencies/ffpack.zip?inline=false");
                }

                client.DownloadFileCompleted += (s, e) =>
                {
                    ZipFile.ExtractToDirectory("ffpack.zip", Directory.GetCurrentDirectory());
                    Form1.instance.DownloadProgress.Invoke(new Action(() =>
                    {
                        Form1.instance.DownloadProgress.Visible = false;
                    }));

                    File.WriteAllText("restart.bat", restartScript);
                    IsBusy = false;

                    Process process = new Process();
                    process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    process.StartInfo.FileName    = "restart.bat";
                    process.Start();
                    Application.Exit();
                };
            }
        }
コード例 #14
0
        /// <summary>
        /// Downloads and installs the latest update.
        /// </summary>
        public static async void DownloadUpdate(bool getPreview)
        {
            IsBusy = true;
            Form1.instance.Log(Localisation.Get("\nDownloading an update..."));
            Form1.instance.ButtonGetUpdate.Visible = false;

            string zipURL = (getPreview ? preview : stable) + "mscmm_update.zip";

            using (WebClient client = new WebClient())
            {
                client.DownloadProgressChanged += (s, e) =>
                {
                    Form1.instance.DownloadProgress.Invoke(new Action(() =>
                    {
                        Form1.instance.DownloadProgress.Visible = true;
                        Form1.instance.DownloadProgress.Value   = e.ProgressPercentage;
                    }));
                    return;
                };

                await Task.Run(() => client.DownloadFileAsync(new Uri(zipURL), "mscmm.zip"));

                client.DownloadFileCompleted += (s, e) =>
                {
                    Form1.instance.Log(Localisation.Get("Extracting..."));
                    Directory.CreateDirectory("update");
                    ZipFile.ExtractToDirectory("mscmm.zip", "update");

                    Form1.instance.Log(Localisation.Get("Installing..."));
                    File.WriteAllText("updater.bat", updaterScript);

                    if (downgrade)
                    {
                        Settings.WipeAll();
                    }

                    IsBusy = false;

                    Process process = new Process();
                    process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    process.StartInfo.FileName    = "updater.bat";
                    process.Start();
                    Application.Exit();
                };
            }
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: Athlon007/msc-ogg
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Sets the working directory to MSCMM install path
            Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            // Loading the localisation file (English (UK).po by default)
            Localisation.LoadLocaleFile();

            if (args.Length > 0)
            {
                switch (args[0])
                {
                default:
                    Application.Run(new QuickConvert(args));
                    break;

                case "wipe":
                    DialogResult dl = MessageBox.Show(Localisation.Get("Are you sure you want to continue?"),
                                                      Localisation.Get("Information"),
                                                      MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Information);

                    if (dl == DialogResult.Yes)
                    {
                        Settings.WipeAll();
                        MessageBox.Show(Localisation.Get("All your settings have been wiped. Restart the MSCMM without 'wipe' argument."),
                                        Localisation.Get("Information"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }

                    Application.Exit();
                    break;

                case "startgame":
                    CustomStartGame.Play();
                    break;
                }
                return;
            }
            Application.Run(new Form1());
        }
コード例 #16
0
 private void btnAudacity_Click(object sender, EventArgs e)
 {
     using (var openFileDialog = new OpenFileDialog())
     {
         openFileDialog.Title            = Localisation.Get("Select the audacity folder.");
         openFileDialog.FileName         = "audacity.exe";
         openFileDialog.Filter           = "Executable (*.exe)|*.exe";
         openFileDialog.InitialDirectory = Directory.Exists("C:\\Program Files (x86)\\Audacity")
             ? "C:\\Program Files (x86)\\Audacity"
             : "C:\\Program Files (x86)";
         var dialog = openFileDialog.ShowDialog();
         if (dialog == DialogResult.OK && openFileDialog.FileName.EndsWith("audacity.exe"))
         {
             Settings.AudacityPath = openFileDialog.FileName;
             txtAudacity.Text      = Settings.AudacityPath;
         }
     }
 }
コード例 #17
0
        /// <summary>
        /// Creates new cover art based of saved coverart.png
        /// </summary>
        /// <param name="cdText"></param>
        /// <param name="folder"></param>
        public void New(string cdText, string folder)
        {
            Form1.instance.Log(Localisation.Get("Creating new cover art for {0}...", folder));

            // Loading the coverart.png image
            CoverArt = (Bitmap)Image.FromFile($"coverart.png");
            // Calculate the cover art scale compared to the default MSC CD cover art (512x512)
            Scale = (double)CoverArt.Width / (double)512;

            // Default starting point for the list of songs (rescaled according to ScaleValue)
            PointF defaultPoint = new PointF(Rescale(274), Rescale(40));
            PointF currentPoint = defaultPoint;
            // By how many pixels does new line appear (scaled)
            int jumpBy = Rescale(19);
            // Maximum ammount of sogns
            int maxSongs = 11;

            // Initialziing Graphics
            using (Graphics graphics = Graphics.FromImage(CoverArt))
            {
                Font font = new Font(Settings.CoverArtFont, Rescale(10));
                // Drawing the text on the CD from cdText
                graphics.DrawString(cdText, new Font(Settings.CoverArtFont,
                                                     Rescale(20)),
                                    Brushes.Black,
                                    new PointF(Rescale(299),
                                               Rescale(415)));

                // Drawing the song names on CD cover
                for (int i = 0; (i < maxSongs) && (i < Player.WorkingSongList.Count); i++)
                {
                    string songName = Player.WorkingSongList[i].Item2;
                    graphics.DrawString(songName, font, Brushes.Black, currentPoint);
                    currentPoint.Y += jumpBy;
                }
            }

            // Saving the edited cover art to the folder
            CoverArt.Save($"{Settings.GamePath}\\{folder}\\coverart.png");
            CoverArt.Dispose();

            Form1.instance.Log(Localisation.Get("Done!"));
            System.Windows.Forms.MessageBox.Show(Localisation.Get("Created CD cover art successfully!"));
        }
コード例 #18
0
ファイル: Player.cs プロジェクト: Athlon007/msc-ogg
        /// <summary>
        /// Plays selected song using ffplay.exe
        /// </summary>
        /// <param name="path">Path to the file</param>
        public static void Play(string path)
        {
            if (!File.Exists("ffplay.exe"))
            {
                MessageBox.Show(Localisation.Get("FFplay is missing! Try to re-download MSC Music Manager."), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Stop();

            process = new Process();
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.CreateNoWindow         = true;

            // Setup executable and parameters
            process.StartInfo.FileName  = "ffplay.exe";
            process.StartInfo.Arguments = $"-nodisp \"{path}\"";
            process.Start();
        }
コード例 #19
0
ファイル: Logs.cs プロジェクト: Athlon007/msc-ogg
        /// <summary>
        /// Dumps the crash log to the file.
        /// </summary>
        /// <param name="log">Crash log content.</param>
        /// <param name="silent">If true, doesn't display crash dialog.</param>
        public static void CrashLog(string log, bool silent = false)
        {
            // Logs disabled? Don't save it
            if (!Settings.Logs)
            {
                return;
            }

            string date = $"{DateTime.Now.Date.Day}.{DateTime.Now.Date.Month}.{DateTime.Now.Date.Year} " +
                          $"{DateTime.Now.Hour.ToString()}.{DateTime.Now.Minute.ToString()}.{DateTime.Now.Second.ToString()}";
            string thisVersion = Application.ProductVersion;
            string fileName    = $"LOG\\{date}.txt";

            Directory.CreateDirectory("LOG");
            File.WriteAllText(fileName,
                              $"// MSC Music Manager //\n" +
                              $"// VERSION: {thisVersion} ({Updates.version})\n" +
                              $"// SYSTEM: {GetSystemInfo()}\n" +
                              $"// MSCMM DIRECTORY: {Directory.GetCurrentDirectory()}\n" +
                              $"// GAME DIRECTORY: {Settings.GamePath}\n" +
                              $"// TIME OF CRASH: {DateTime.Now}\n" +
                              $"// LANGUAGE: {Settings.Language}\n\n" +
                              $"// {GetWittyComment()}\n\n" +
                              $"{log}");

            Settings.LastCrashLogFile = $"{date}.txt";

            if (silent)
            {
                return;
            }

            DialogResult dl = MessageBox.Show(Localisation.Get("An error has occured. Log has been saved into LOG folder. " +
                                                               "Would you like to open it now?"), Localisation.Get("Error"), MessageBoxButtons.YesNo, MessageBoxIcon.Error);

            if (dl == DialogResult.Yes)
            {
                Process.Start(fileName);
            }
        }
コード例 #20
0
ファイル: MoveTo.cs プロジェクト: Athlon007/msc-ogg
        public MoveTo(string[] files, string sourceFolder)
        {
            InitializeComponent();

            Localise();
            Message = Localisation.Get("Where do you want to move {0} file(s)?", files.Length);

            this.files        = files;
            this.sourceFolder = sourceFolder;

            selectedFolder.SelectedIndex = 0;

            if (Directory.Exists($"{Settings.GamePath}\\CD1") && !Directory.Exists($"{Settings.GamePath}\\CD"))
            {
                selectedFolder.Items.RemoveAt(1);
            }
            else
            {
                selectedFolder.Items.RemoveAt(4);
                selectedFolder.Items.RemoveAt(3);
                selectedFolder.Items.RemoveAt(2);
            }
        }
コード例 #21
0
        /// <summary>
        /// Downloads youtube-dl directly from youtube-dl servers
        /// </summary>
        /// <returns></returns>
        public static async Task GetYoutubeDl()
        {
            IsYoutubeDlUpdating = true;
            Form1.instance.Log(Localisation.Get("\nDownloading youtube-dl..."));
            try
            {
                using (WebClient web = new WebClient())
                {
                    web.DownloadProgressChanged += (s, e) =>
                    {
                        Form1.instance.DownloadProgress.Invoke(new Action(() =>
                        {
                            Form1.instance.DownloadProgress.Visible = true;
                            Form1.instance.DownloadProgress.Value   = e.ProgressPercentage;
                        }));
                        return;
                    };

                    await Task.Run(() => web.DownloadFileAsync(new Uri("https://yt-dl.org/latest/youtube-dl.exe"), "youtube-dl.exe"));

                    web.DownloadFileCompleted += (s, e) =>
                    {
                        Form1.instance.DownloadProgress.Invoke(new Action(() => Form1.instance.DownloadProgress.Visible = false));
                        IsYoutubeDlUpdating = false;
                        Form1.instance.Log(Localisation.Get("youtube-dl downloaded successfully!"));
                        Form1.instance.Invoke(new Action(() => Form1.instance.RestrictedMode(false)));
                    };
                }
            }
            catch (Exception ex)
            {
                Form1.instance.Log(Localisation.Get("Couldn't download youtube-dl. Crash log has been created."));
                Logs.CrashLog(ex.ToString());
                IsYoutubeDlUpdating = false;
                return;
            }
        }
コード例 #22
0
ファイル: Player.cs プロジェクト: Athlon007/msc-ogg
        /// <summary>
        ///  Moves file to opposite folder (ex. from Radio to CD and vice versa)
        /// </summary>
        /// <param name="fileName">File name that we want to move</param>
        /// <param name="source">From where the files are being moves</param>
        /// <param name="destination">Where to files are moved</param>
        public static void MoveTo(string fileName, string source, string destination)
        {
            if (Utilities.IsToolBusy())
            {
                MessageBox.Show(Localisation.Get("Program is busy."), Localisation.Get("Stop"), MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            IsBusy = true;
            Stop();

            try
            {
                int newNumber = Utilities.GetNewFileNumber(destination);

                // Waiting for file to be free
                while (!Utilities.IsFileReady($"{Settings.GamePath}\\{source}\\{fileName}.ogg"))
                {
                }
                File.Move($"{Settings.GamePath}\\{source}\\{fileName}.ogg", $"{Settings.GamePath}\\{destination}\\track{newNumber}.ogg");
                MetaData.MoveToDatabase(source, fileName, destination, $"track{newNumber}");

                Logs.History(Localisation.Get("File Moving: moved '{0}' from '{1}' to '{2}' as 'track{3}'", fileName, source, destination, newNumber));
                Form1.instance.Log(Localisation.Get("File Moving: moved '{0}' from '{1}' to '{2}' as 'track{3}'", fileName, source, destination, newNumber));
            }
            catch (Exception ex)
            {
                ErrorMessage err = new ErrorMessage(ex);
                err.ShowDialog();
            }
            finally
            {
                IsBusy = false;
                Form1.instance.UpdateSongList();
            }
        }
コード例 #23
0
ファイル: Player.cs プロジェクト: Athlon007/msc-ogg
        /// <summary>
        /// Clones song and gives it correct name
        /// </summary>
        /// <param name="folder">Current folder (radio or cd)</param>
        /// <param name="fileName">File name</param>
        public static void Clone(string folder, string fileName)
        {
            if (Utilities.IsToolBusy())
            {
                MessageBox.Show(Localisation.Get("Program is busy."), Localisation.Get("Stop"), MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            IsBusy = true;
            string newName = null;

            try
            {
                // Getting a new name for cloned song
                int newNumber = Utilities.GetNewFileNumber("folder");

                newName = $"track{newNumber}";

                string pathToFile = $"{Settings.GamePath}\\{folder}\\{fileName}"; // Path to file to be cloned with it's name

                File.Copy($"{pathToFile}.ogg", $"{Settings.GamePath}\\{folder}\\{newName}.ogg");
                MetaData.AddOrEdit(newName, MetaData.GetName(fileName));

                Logs.History(Localisation.Get("Cloned '{0}' to '{1}' in {2}", fileName, newName, folder));
                Form1.instance.Log(Localisation.Get("Cloned '{0}' to '{1}' in {2}", fileName, newName, folder));
            }
            catch (Exception ex)
            {
                ErrorMessage err = new ErrorMessage(ex);
                err.ShowDialog();
            }
            finally
            {
                IsBusy = false;
            }
        }
コード例 #24
0
ファイル: Utilities.cs プロジェクト: Athlon007/msc-ogg
        /// <summary>
        /// Connects to GitLab and checks if it's (or computer) is online
        /// </summary>
        public static bool IsOnline()
        {
            if (isOffline)
            {
                return(false);
            }

            try
            {
                using (WebClient client = new WebClient())
                {
                    using (client.OpenRead("https://gitlab.com/aathlon/msc-ogg"))
                    {
                        return(true);
                    }
                }
            }
            catch
            {
                Form1.instance.Log(Localisation.Get("Looks like you're offline. Can't check for the update availability"));
                isOffline = true;
                return(false);
            }
        }
コード例 #25
0
ファイル: Converter.cs プロジェクト: Athlon007/msc-ogg
        /// <summary>
        /// Starts the conversion of every found file in Radio or CD
        /// </summary>
        public static async void StartConversion()
        {
            if (Utilities.IsToolBusy())
            {
                Form1.instance.Log(Localisation.Get("Program is busy."));
                return;
            }

            if (Settings.GamePath.Length == 0)
            {
                Form1.instance.Log(Localisation.Get("Select the game path first."));
                return;
            }

            Converter.IsBusy           = true;
            Converter.TotalConversions = 0;
            Converter.Skipped          = 0;

            try
            {
                Form1.instance.RestrictedMode(true);
                Form1.instance.Log("\n-----------------------------------------------------------------------------------------------------------------------------------------");
                await Task.Run(() => Converter.ConvertFolder("Radio", 99));

                if (Directory.Exists($"{Settings.GamePath}\\CD") && !Directory.Exists($"{Settings.GamePath}\\CD1"))
                {
                    await Converter.ConvertFolder("CD", 15);
                }
                else
                {
                    // Added with the new update
                    for (int i = 1; i <= 3; i++)
                    {
                        await Task.Run(() => Converter.ConvertFolder($"CD{i}", 15));
                    }
                }

                if (Converter.Skipped != 4)
                {
                    Form1.instance.Log(Localisation.Get("\nDone!"));
                    Form1.instance.Log(Localisation.Get("Converted {0} file(s) in total", Converter.TotalConversions));
                    Form1.instance.Log(Localisation.Get("Conversion log was saved to history.txt"));
                }
                else
                {
                    Form1.instance.Log(Localisation.Get("Conversion log will not be saved, because both Radio and CDs were skipped"));
                }

                SystemSounds.Exclamation.Play();
            }
            catch (Exception ex)
            {
                ErrorMessage err = new ErrorMessage(ex);
                err.ShowDialog();
            }
            finally
            {
                Converter.IsBusy = false;
                Form1.instance.RestrictedMode(false);
            }

            Form1.instance.UpdateSongList();
        }
コード例 #26
0
ファイル: Converter.cs プロジェクト: Athlon007/msc-ogg
        /// <summary>
        /// Works like ConvertFolder, but instead it just converts single file.
        /// </summary>
        /// <param name="filePath">Path to the file.</param>
        /// <param name="folder">Folder to what we want to convert (CD or Radio)</param>
        /// <param name="limit">Limit of files - My Summer Car uses maximum of 15 files for CD and 99 for Radio</param>
        /// <param name="forcedName">If set, instead of getting name from ffmpeg output, it will get it from forcedName.</param>
        /// <returns></returns>
        public static async Task ConvertFile(string filePath, string folder, int limit, string altName = "", bool forceAltName = false)
        {
            if (!File.Exists($"{Directory.GetCurrentDirectory()}\\ffmpeg.exe"))
            {
                MessageBox.Show("FFmpeg.exe is missing! Try to re-download MSC Music Manager.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!filePath.ContainsAny(extensions))
            {
                if (Form1.instance != null)
                {
                    Form1.instance.Log(Localisation.Get("'{0}' is not a recognizable music file, so it will be skipped.",
                                                        filePath.Substring(filePath.LastIndexOf('\\') + 1)));
                }
                return;
            }

            int inGame = Utilities.GetNewFileNumber(folder);

            if (Form1.instance != null)
            {
                Form1.instance.Log(Localisation.Get("\nConverting '{0}'\n", filePath.Substring(filePath.LastIndexOf('\\') + 1)));
            }

            FfmpegOutput = "";

            try
            {
                MetaData.AlternateFolder = folder;

                if ((limit != 0) && (inGame > limit) && (!Settings.IgnoreLimitations))
                {
                    DialogResult res = MessageBox.Show(
                        Localisation.Get("There's over {0} files in {1} already converted. " +
                                         "My Summer Car allows max {0} files for {1} and any file above that will be ignored. " +
                                         "Would you like to continue?", limit, folder),
                        Localisation.Get("Stop"),
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Information);

                    if (res == DialogResult.No)
                    {
                        if (Form1.instance != null)
                        {
                            Form1.instance.Log(Localisation.Get("Aborted {0} conversion.", folder));
                        }
                        return;
                    }
                }

                string songName  = "";
                string arguments = $"-i \"{filePath}\" -acodec libvorbis \"{Settings.GamePath}\\{folder}\\track{inGame}.ogg\"";

                // If it's just OGG file - instead of converting, simply rename it
                if (filePath.EndsWith(".ogg"))
                {
                    File.Move(filePath, $"{Settings.GamePath}\\{folder}\\track{inGame}.ogg");
                    arguments = $"-i \"{Settings.GamePath}\\{folder}\\track{inGame}.ogg\"";
                }

                Process process = new Process();
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.CreateNoWindow         = true;
                process.StartInfo.FileName  = "ffmpeg.exe";
                process.StartInfo.Arguments = arguments;
                process.ErrorDataReceived  += new DataReceivedEventHandler(OutputHandler);
                await Task.Run(() => process.Start());

                process.BeginErrorReadLine();
                await Task.Run(() => process.WaitForExit());

                if (altName == null)
                {
                    string[] ffmpegOut = FfmpegOutput.Split('\n');
                    songName = MetaData.GetFromOutput(ffmpegOut);
                    if ((songName == " - " || songName == "") && altName != "")
                    {
                        songName = altName;
                    }
                }
                else
                {
                    songName = altName;
                }

                MetaData.AddOrEdit($"track{inGame}", songName);

                Logs.History(Localisation.Get("Added '{0}' (track{1}.ogg) in {2}", songName, inGame, folder));

                if (Form1.instance != null)
                {
                    Form1.instance.Log(Localisation.Get("Finished '{0}' as 'track{1}.ogg'",
                                                        filePath.Substring(filePath.LastIndexOf('\\') + 1), inGame));
                }
            }
            catch (Exception ex)
            {
                ErrorMessage err = new ErrorMessage(ex);
                err.ShowDialog();
            }
            finally
            {
                MetaData.AlternateFolder = "";
            }
        }
コード例 #27
0
ファイル: Converter.cs プロジェクト: Athlon007/msc-ogg
        /// <summary>
        /// Converts all files found in the folder
        /// </summary>
        /// <param name="folder">Folder to convert (CD or Radio)</param>
        /// <param name="limit">Limit of files - My Summer Car uses maximum of 15 files for CD and 99 for Radio</param>
        /// <returns></returns>
        public static async Task ConvertFolder(string folder, int limit)
        {
            if (!File.Exists("ffmpeg.exe"))
            {
                MessageBox.Show(Localisation.Get("FFmpeg.exe is missing! Try to re-download MSC Music Manager."),
                                Localisation.Get("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Form1.instance.Log(Localisation.Get("Initializing {0} conversion...\n", folder));
            string path = $"{Settings.GamePath}\\{folder}";

            FfmpegOutput = "";

            if (!Directory.Exists(path))
            {
                Form1.instance.Log(Localisation.Get("Skipping {0} because it doesn't exist...", folder));
                return;
            }

            try
            {
                MetaData.AlternateFolder = folder;

                DirectoryInfo d = new DirectoryInfo(path);
                FileInfo[]    files
                    = d.GetFiles()
                      .Where(f => extensions.Contains(f.Extension.ToLower()) && !f.Name.StartsWith("track"))
                      .ToArray();

                // If no files have been found - aborts the conversion
                if (files.Length == 0)
                {
                    Form1.instance.Log(Localisation.Get("Couldn't find any file to convert in {0}", folder));
                    Skipped++;
                    return;
                }

                // Counts how many files there are in game + after that variable new files are named
                int inGame = Utilities.GetNewFileNumber(folder);

                // Starting the conversion of all found files
                foreach (FileInfo file in files)
                {
                    // Prevents overwriting existing files, if there's an gap between them
                    while (File.Exists($"{path}\\track{inGame}.ogg"))
                    {
                        inGame++;
                    }

                    // If the limit of files per folder is applied, checks if it isn't over it
                    if ((limit != 0) && (inGame > limit) && (!Settings.IgnoreLimitations))
                    {
                        DialogResult res = MessageBox.Show(
                            Localisation.Get("There's over {0} files in {1} already converted. " +
                                             "My Summer Car allows max {0} files for {1} and any file above that will be ignored. " +
                                             "Would you like to continue?", limit, folder),
                            Localisation.Get("Stop"),
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Information);

                        if (res == DialogResult.No)
                        {
                            Form1.instance.Log(Localisation.Get("Aborted {0} conversion.", folder));
                            break;
                        }
                    }

                    Form1.instance.Log(Localisation.Get("Converting {0}", file.Name));

                    string songName = null;
                    string argument = $"-i \"{path}\\{file.Name}\" -acodec libvorbis"
                                      + (Settings.UseRecommendedFrequency ? " -ar 22050" : "")
                                      + (Settings.ConvertToMono ? " -ac 1" : "")
                                      + " \"{path}\\track{inGame}.ogg\"";

                    // If the file is already in OGG format - rename file, and start FFmpeg in order to try and find the name
                    if (file.Name.EndsWith(".ogg") && !file.Name.StartsWith("track"))
                    {
                        File.Move($"{path}\\{file.Name}", $"{path}\\track{inGame}.ogg");
                        argument = $"-i \"{path}\\track{inGame}.ogg\"";
                    }

                    Process process = new Process();
                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.RedirectStandardError  = true;
                    process.StartInfo.CreateNoWindow         = true;
                    process.StartInfo.FileName  = "ffmpeg.exe";
                    process.StartInfo.Arguments = argument;
                    process.ErrorDataReceived  += new DataReceivedEventHandler(OutputHandler);
                    await Task.Run(() => process.Start());

                    process.BeginErrorReadLine();
                    await Task.Run(() => process.WaitForExit());

                    songName = MetaData.GetFromOutput(FfmpegOutput.Split('\n'));
                    songName = String.IsNullOrEmpty(songName) ? file.Name.Split('.')[0] : songName;
                    MetaData.AddOrEdit($"track{inGame}", songName);

                    Form1.instance.Log(Localisation.Get("Finished {0} as track{1}.ogg", file.Name, inGame));

                    File.Delete($"{path}\\{file.Name}");

                    Logs.History(Localisation.Get("Added '{0}' (track{1}.ogg) in {2}", songName, inGame, folder));

                    inGame++;
                    TotalConversions++;
                }
            }
            catch (Exception ex)
            {
                ErrorMessage err = new ErrorMessage(ex);
                err.ShowDialog();
            }
            finally
            {
                MetaData.AlternateFolder = null;
            }

            Form1.instance.Log(Localisation.Get("Converted {0} file(s) in {1}", TotalConversions, folder));
        }
コード例 #28
0
ファイル: Downloader.cs プロジェクト: Athlon007/msc-ogg
        /// <summary>
        /// Downloads the song as .ACC file
        /// </summary>
        /// <param name="url">URL link to video</param>
        /// <param name="folder">Radio or CD</param>
        /// <param name="limit">Radio = 99. CD = 15</param>
        /// <returns></returns>
        public static async Task DownloadFile(string url, string folder, int limit, string forcedName = null)
        {
            try
            {
                CancelDownload = false;

                Form1.instance.DownloadProgress.Visible = false;

                IsBusy = true;

                if (File.Exists("download.aac"))
                {
                    File.Delete("download.aac");
                }

                Form1.instance.YoutubeDlLog(Localisation.Get("\nDownloading song..."));
                Logs.History(Localisation.Get("Downloader: Downloading song from '{0}'", url));

                Process process = new Process();
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.CreateNoWindow         = true;

                // Setup executable and parameters
                process.StartInfo.FileName = "youtube-dl.exe";
                int audioQuality = GetAudioQuality();
                process.StartInfo.Arguments = $"-f bestaudio -x --audio-format mp3 --audio-quality {audioQuality} -o \"download.%(ext)s\" {url}";

                if (CancelDownload)
                {
                    CancelDownload = true;
                    return;
                }

                process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
                Form1.instance.ClearYtLog();

                await Task.Run(() => process.Start());

                process.BeginOutputReadLine();
                await Task.Run(() => process.WaitForExit());

                Logs.History("-- youtube-dl output: --\n" + Form1.instance.GetYtDlLog);
                Form1.instance.YoutubeDlLog("\n\n====================================\nDone!");

                // File wasn't downloaded?
                if (!File.Exists("download.mp3"))
                {
                    Form1.instance.YoutubeDlLog(Localisation.Get("Couldn't donwnload the song.\n" +
                                                                 "If you canceled the download, then everything's fine.\n" +
                                                                 "If not, check if there's a youtube-dl update, by clicking Tool -> Check for youtube-dl update.\n" +
                                                                 "Also please check if youtube-dl supports the link that you use: " +
                                                                 "https://ytdl-org.github.io/youtube-dl/supportedsites.html. \n" +
                                                                 "If it's going to happen again, please send the history.txt file content to developer on Steam, or via mail."));
                    IsBusy = false;
                    Form1.instance.RestrictedMode(false);
                    return;
                }

                Form1.instance.YoutubeDlLog(Localisation.Get("Converting..."));

                if (CancelDownload)
                {
                    CancelDownload = true;
                    return;
                }

                // Forced name is empty? Try to get the name from link
                if (String.IsNullOrEmpty(forcedName))
                {
                    forcedName = GetTitleFromYouTube(url);
                }

                await Converter.ConvertFile($"{Directory.GetCurrentDirectory()}\\download.mp3", folder, limit, forcedName, true);

                File.Delete("download.mp3");
                IsBusy = false;

                Form1.instance.UpdateSongList();
                Form1.instance.RestrictedMode(false);
            }
            catch (Exception) when(CancelDownload)
            {
                Form1.instance.YoutubeDlLog(Localisation.Get("Canceled!"));
            }
        }
コード例 #29
0
ファイル: Downloader.cs プロジェクト: Athlon007/msc-ogg
        /// <summary>
        /// Downloads all songs from playlist
        /// </summary>
        /// <param name="url"></param>
        /// <param name="folder"></param>
        /// <param name="limit"></param>
        public async static Task DownloadPlaylist(string url, string folder, int limit)
        {
            try
            {
                CancelDownload = false;

                Form1.instance.DownloadProgress.Visible = false;

                IsBusy = true;

                if (Directory.Exists("downloads"))
                {
                    Directory.Delete("downloads", true);
                }

                Directory.CreateDirectory("downloads");

                Form1.instance.YoutubeDlLog(Localisation.Get("\nDownloading playlist..."));
                Logs.History(Localisation.Get("Downloader: Downloading playlist from '{0}'", url));

                Process process = new Process();
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.CreateNoWindow         = true;

                // Setup executable and parameters
                process.StartInfo.FileName = "youtube-dl.exe";
                int audioQuality = GetAudioQuality();
                process.StartInfo.Arguments = $"-f bestaudio -x --audio-format mp3 --audio-quality {audioQuality} -o \"downloads\\%(title)s.%(ext)s\" {url}";

                if (CancelDownload)
                {
                    CancelDownload = true;
                    return;
                }

                process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
                Form1.instance.ClearYtLog();

                await Task.Run(() => process.Start());

                process.BeginOutputReadLine();
                await Task.Run(() => process.WaitForExit());

                Logs.History("-- youtube-dl output: --\n" + Form1.instance.GetYtDlLog);
                Form1.instance.YoutubeDlLog("\n\n====================================\nDone!");

                // File wasn't downloaded?
                if (Directory.GetFiles("downloads").Length == 0)
                {
                    Form1.instance.YoutubeDlLog(Localisation.Get("Couldn't donwnload the song.\n" +
                                                                 "If you canceled the download, then everything's fine.\n" +
                                                                 "If not, check if there's a youtube-dl update, by clicking Tool -> Check for youtube-dl update.\n" +
                                                                 "Also please check if youtube-dl supports the link that you use: " +
                                                                 "https://ytdl-org.github.io/youtube-dl/supportedsites.html. \n" +
                                                                 "If it's going to happen again, please send the history.txt file content to developer on Steam, or via mail."));
                    IsBusy = false;
                    Form1.instance.RestrictedMode(false);
                    return;
                }

                Form1.instance.YoutubeDlLog(Localisation.Get("Converting..."));

                if (CancelDownload)
                {
                    CancelDownload = true;
                    return;
                }

                DirectoryInfo di    = new DirectoryInfo("downloads");
                FileInfo[]    files = di.GetFiles("*.mp3");

                foreach (var file in files)
                {
                    string name = file.Name.Split('.')[0];
                    await Converter.ConvertFile($"{file.FullName}", folder, limit, name);
                }

                Directory.Delete("downloads", true);
                IsBusy = false;

                Form1.instance.UpdateSongList();
                Form1.instance.RestrictedMode(false);
            }
            catch (Exception) when(CancelDownload)
            {
                Form1.instance.YoutubeDlLog(Localisation.Get("Canceled!"));
            }
        }
コード例 #30
0
ファイル: QuickConvert.cs プロジェクト: Athlon007/msc-ogg
 void Localise()
 {
     btnApply.Text = Localisation.Get("Apply");
     btnExit.Text  = Localisation.Get("Exit");
     this.Text     = Localisation.Get("Quick Convert");
 }