Esempio n. 1
0
        private static void To(string[] args)
        {
            string input  = args[2];
            string output = args[3];
            bool   loop   = false;
            bool   mono   = false;

            //Check if file exists
            if (File.Exists(input) == false)
            {
                Console.WriteLine("ERROR: Unable to open file: {0}", input);
                Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it.");
                Console.WriteLine("Error: SHARPII_NET_CORE_BNS_FILE_ERR");
                if (OperatingSystem.Windows())
                {
                    Environment.Exit(0x00003E81);
                }
                else
                {
                    Environment.Exit(0x00000003);
                }
                return;
            }

            for (int i = 1; i < args.Length; i++)
            {
                switch (args[i].ToUpper())
                {
                case "-L":
                    loop = true;
                    break;

                case "-LOOP":
                    loop = true;
                    break;

                case "-M":
                    mono = true;
                    break;

                case "-MONO":
                    mono = true;
                    break;
                }
            }

            //Run main part, and check for exceptions
            try
            {
                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Loading file...");
                }

                BNS WavFile = new BNS(input);

                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Done!\n");
                }

                if (loop == true)
                {
                    if (BeQuiet.quiet > 2)
                    {
                        Console.WriteLine("Applying loop");
                    }
                    WavFile.SetLoop(1);
                }
                if (mono == true)
                {
                    if (BeQuiet.quiet > 2)
                    {
                        Console.WriteLine("Converting to mono");
                    }
                    WavFile.StereoToMono = true;
                }

                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Saving BNS...");
                }

                WavFile.Convert();

                if (output.Substring(output.Length - 4, 4).ToUpper() != ".BNS")
                {
                    output += ".bns";
                }

                WavFile.Save(output);

                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Done!\n");
                }

                if (BeQuiet.quiet > 1)
                {
                    Console.WriteLine("Operation completed succesfully!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("An unknown error occured, please try again");
                Console.WriteLine("");
                Console.WriteLine("ERROR DETAILS: {0}", ex.Message);
                Console.WriteLine("Error: SHARPII_NET_CORE_BNS_UNKNOWN");
                if (OperatingSystem.Windows())
                {
                    Environment.Exit(0x00003E82);
                }
                else
                {
                    Environment.Exit(0x00000004);
                }
                return;
            }
        }
Esempio n. 2
0
        void bwConvertToBns_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                BackgroundWorker  bwConvertToBns = sender as BackgroundWorker;
                BnsConversionInfo bnsInfo        = (BnsConversionInfo)e.Argument;
                byte[]            audioData      = new byte[0];

                if (bnsInfo.audioFile.ToLower() == "internal sound")
                {
                    for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++)
                    {
                        if (sourceWad.BannerApp.StringTable[i].ToLower() == "sound.bin")
                        {
                            audioData = Headers.IMD5.RemoveHeader(sourceWad.BannerApp.Data[i]);
                        }
                    }

                    internalSound = true;
                }
                else
                {
                    audioData = File.ReadAllBytes(bnsInfo.audioFile);
                }

                bool mp3 = bnsInfo.audioFile.EndsWith(".mp3");
                if (mp3 && bnsInfo.loopType == BnsConversionInfo.LoopType.FromWave)
                {
                    bnsInfo.loopType = BnsConversionInfo.LoopType.None;
                }

                if (mp3)
                {
                    bwConvertToBns.ReportProgress(0, "Converting MP3...");

                    ProcessStartInfo lameI = new ProcessStartInfo(Application.StartupPath + Path.DirectorySeparatorChar + "lame.exe",
                                                                  string.Format("--decode \"{0}\" \"{1}\"", bnsInfo.audioFile, Application.StartupPath + Path.DirectorySeparatorChar + "customizemii_temp.wav"));
                    lameI.CreateNoWindow        = true;
                    lameI.UseShellExecute       = false;
                    lameI.RedirectStandardError = true;

                    Process lame = Process.Start(lameI);

                    string thisLine = string.Empty;
                    while (lame.HasExited == false)
                    {
                        thisLine = lame.StandardError.ReadLine();
                        if (!string.IsNullOrEmpty(thisLine))
                        {
                            if (thisLine.StartsWith("Frame#"))
                            {
                                string thisFrame = thisLine.Remove(thisLine.IndexOf('/'));
                                thisFrame = thisFrame.Remove(0, thisFrame.LastIndexOf(' ') + 1);
                                string Frames = thisLine.Remove(0, thisLine.IndexOf('/') + 1);
                                Frames = Frames.Remove(Frames.IndexOf(' '));

                                int thisProgress = (int)((Convert.ToDouble(thisFrame) / Convert.ToDouble(Frames)) * 100);
                                bwConvertToBns.ReportProgress(thisProgress);
                            }
                        }
                    }

                    lame.WaitForExit();
                    lame.Close();

                    if (File.Exists(Application.StartupPath + Path.DirectorySeparatorChar + "customizemii_temp.wav"))
                    {
                        audioData = File.ReadAllBytes(Application.StartupPath + Path.DirectorySeparatorChar + "customizemii_temp.wav");
                        File.Delete(Application.StartupPath + Path.DirectorySeparatorChar + "customizemii_temp.wav");
                    }
                    else
                    {
                        throw new Exception("Error converting MP3...");
                    }
                }

                bwConvertToBns.ReportProgress(0, "Converting to BNS...");

                BNS bns = new BNS(audioData, bnsInfo.loopType == BnsConversionInfo.LoopType.FromWave);
                bns.Progress += new EventHandler <ProgressChangedEventArgs>(bns_ProgressChanged);

                bns.StereoToMono = bnsInfo.stereoToMono;
                bns.Convert();

                if (bnsInfo.loopType == BnsConversionInfo.LoopType.Manual && bnsInfo.loopStartSample > -1 && bnsInfo.loopStartSample < bns.TotalSampleCount)
                {
                    bns.SetLoop(bnsInfo.loopStartSample);
                }

                newSoundBin   = Headers.IMD5.AddHeader(bns.ToByteArray());
                replacedSound = bnsInfo.audioFile;
            }
            catch (Exception ex)
            {
                replacedSound = string.Empty;
                if (File.Exists(Application.StartupPath + Path.DirectorySeparatorChar + "customizemii_temp.wav"))
                {
                    File.Delete(Application.StartupPath + Path.DirectorySeparatorChar + "customizemii_temp.wav");
                }
                errorBox("Error during conversion:\n" + ex.Message);
            }
        }
Esempio n. 3
0
        private static void To(string[] args)
        {
            string input  = args[2];
            string output = args[3];
            bool   loop   = false;
            bool   mono   = false;

            //Check if file exists
            if (File.Exists(input) == false)
            {
                Console.WriteLine("ERROR: Unable to open file: {0}", input);
                return;
            }

            for (int i = 1; i < args.Length; i++)
            {
                switch (args[i].ToUpper())
                {
                case "-L":
                    loop = true;
                    break;

                case "-LOOP":
                    loop = true;
                    break;

                case "-M":
                    mono = true;
                    break;

                case "-MONO":
                    mono = true;
                    break;
                }
            }

            //Run main part, and check for exceptions
            try
            {
                if (Quiet.quiet > 2)
                {
                    Console.Write("Loading file...");
                }

                BNS WavFile = new BNS(input);

                if (Quiet.quiet > 2)
                {
                    Console.Write("Done!\n");
                }

                if (loop == true)
                {
                    if (Quiet.quiet > 2)
                    {
                        Console.WriteLine("Applying loop");
                    }
                    WavFile.SetLoop(1);
                }
                if (mono == true)
                {
                    if (Quiet.quiet > 2)
                    {
                        Console.WriteLine("Converting to mono");
                    }
                    WavFile.StereoToMono = true;
                }

                if (Quiet.quiet > 2)
                {
                    Console.Write("Saving BNS...");
                }

                WavFile.Convert();

                if (output.Substring(output.Length - 4, 4).ToUpper() != ".BNS")
                {
                    output = output + ".bns";
                }

                WavFile.Save(output);

                if (Quiet.quiet > 2)
                {
                    Console.Write("Done!\n");
                }

                if (Quiet.quiet > 1)
                {
                    Console.WriteLine("Operation completed succesfully!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("An unknown error occured, please try again");
                Console.WriteLine("");
                Console.WriteLine("ERROR DETAILS: {0}", ex.Message);
                return;
            }
        }