Beispiel #1
0
        //FSB内のすべてのファイルを抽出
        static RESULT Extract_All_Files(string FSBFileStr, string To_Dir, ref List <string> Output_Files)
        {
            RESULT FModResult;
            Sound  FModSound = new Sound();

            FModResult = Fmod_System.FModSystem.createSound(FSBFileStr, MODE.SOFTWARE | MODE.CREATESTREAM | MODE.ACCURATETIME, ref FModSound);
            if (FModResult != RESULT.OK)
            {
                Sub_Code.Error_Log_Write(Error.String(FModResult));
                return(FModResult);
            }
            else
            {
                //FSB内のファイル数を取得
                List <string> Names    = Fmod_Class.FSB_GetNames(FSBFileStr);
                Sound         SubSound = new Sound();
                //残りのファイルがなくなるまで続ける
                for (int i = 0; i < Names.Count; i++)
                {
                    if (FModSound.getSubSound(i, ref SubSound) == RESULT.OK)
                    {
                        SubSound.seekData(0);
                        //今のところwav形式しか対応していません(.wav以外はffmpegでエンコードします)
                        FileStream SubSoundStream = new FileStream(To_Dir + @"\" + Names[i] + ".wav", FileMode.Create, FileAccess.Write);
                        Output_Files.Add(To_Dir + "\\" + Names[i] + ".wav");
                        uint Length = WriteHeader(SubSoundStream, SubSound);
                        do
                        {
                            //音をファイルに出力(1度に65536バイトしか入らないためループさせる)
                            byte[] SoundData = new byte[65536];
                            uint   LenToRead;
                            if (Length > SoundData.Length)
                            {
                                LenToRead = 65536;
                            }
                            else
                            {
                                LenToRead = Length;
                            }
                            uint   LenRead   = LenToRead;
                            IntPtr BufferPtr = Marshal.AllocHGlobal((int)LenToRead);
                            FModResult = SubSound.readData(BufferPtr, LenToRead, ref LenRead);
                            Marshal.Copy(BufferPtr, SoundData, 0, (int)LenRead);
                            SubSoundStream.Write(SoundData, 0, (int)LenRead);
                            Marshal.FreeHGlobal(BufferPtr);
                            Length -= LenRead;
                        } while ((Length > 0) && (FModResult == RESULT.OK));
                        long FileSize = SubSoundStream.Position;
                        SubSoundStream.Seek(4, SeekOrigin.Begin);
                        SubSoundStream.Write(BitConverter.GetBytes((long)(FileSize - 8)), 0, 4);
                        SubSoundStream.Close();
                    }
                    SubSound.release();
                }
                FModSound.release();
            }
            return(FModResult);
        }
Beispiel #2
0
        //抽出開始
        private async void Extract_B_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (IsClosing)
            {
                return;
            }
            if (Select_L.SelectedIndex == -1)
            {
                Message_Feed_Out("適応元が指定されていません。");
                return;
            }
            if (Extract_L.SelectedIndex == -1)
            {
                Message_Feed_Out("出力形式が指定されていません。");
                return;
            }
            if (FSB_Name_L.Items.Count == 0)
            {
                Message_Feed_Out("FSBファイルが選択されていません。");
                return;
            }
            if (Select_L.SelectedIndex == 1 && FSB_Name_L.SelectedIndex == -1)
            {
                Message_Feed_Out("リスト内のファイルが選択されていません。");
                return;
            }
            if (Extract_L.SelectedIndex == 0 || Extract_L.SelectedIndex == 5)
            {
                string           Message = ".aacと.webm形式はこのソフトでは再エンコード(fsbに戻す作業)ができなくなります。よろしいですか?";
                MessageBoxResult result  = MessageBox.Show(Message, "確認", MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.No);
                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }
            //抽出元が選択したファイルのみの場合
            if (Select_L.SelectedIndex == 1)
            {
                System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.Title  = "保存先を指定してください。";
                sfd.Filter = "音声ファイル(*" + Extract_L.SelectedItem + ")|*" + Extract_L.SelectedItem;
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Message_T.Text = "FSBファイルから抽出しています...";
                    await Task.Delay(50);

                    string File_Name = sfd.FileName.Replace(Path.GetExtension(sfd.FileName), "");
                    if (Fmod_File_Extract_V1.FSB_Extract_To_File(File_Full_Name, FSB_Name_L.SelectedIndex, File_Name + ".wav"))
                    {
                        if (Extract_L.SelectedIndex != 4)
                        {
                            Message_T.Text = Extract_L.SelectedItem.ToString().Replace(".", "").ToUpper() + "にエンコードしています...";
                            await Task.Delay(5);

                            Sub_Code.Audio_Encode_To_Other(File_Name + ".wav", File_Name + Extract_L.SelectedItem, Extract_L.SelectedItem.ToString(), true);
                        }
                    }
                    else
                    {
                        Message_Feed_Out("抽出できませんでした。");
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            //抽出元がすべてのファイルの場合
            else
            {
                BetterFolderBrowser ofd = new BetterFolderBrowser()
                {
                    Title       = "抽出先のフォルダを選択してください。",
                    RootFolder  = Sub_Code.Get_OpenDirectory_Path(),
                    Multiselect = false
                };
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Sub_Code.Set_Directory_Path(ofd.SelectedFolder);
                    try
                    {
                        Message_T.Text = "FSBファイルから抽出しています...";
                        await Task.Delay(50);

                        List <string> Name_Delete = Fmod_Class.FSB_GetNames(File_Full_Name);
                        foreach (string Name_Now in Name_Delete)
                        {
                            if (Sub_Code.File_Exists(ofd.SelectedFolder + "/" + Name_Now))
                            {
                                Sub_Code.File_Delete(ofd.SelectedFolder + "/" + Name_Now);
                            }
                        }
                        //.wavに変換されたファイルパスすべてを取得し指定した形式にエンコード(形式がwavだった場合を除く)
                        if (Fmod_File_Extract_V2.FSB_Extract_To_Directory(File_Full_Name, ofd.SelectedFolder))
                        {
                            //FSBのファイル構成を保存&エンコード
                            StreamWriter stw          = File.CreateText(ofd.SelectedFolder + "/" + Path.GetFileNameWithoutExtension(File_Full_Name) + ".tmp");
                            string[]     Output_Files = Directory.GetFiles(ofd.SelectedFolder, "*.wav", SearchOption.TopDirectoryOnly);
                            foreach (string File_Now in Output_Files)
                            {
                                if (Extract_L.SelectedIndex != 4)
                                {
                                    Message_T.Text = Path.GetFileNameWithoutExtension(File_Now) + "をエンコードしています...";
                                    await Task.Delay(5);

                                    Sub_Code.Audio_Encode_To_Other(File_Now, Path.GetDirectoryName(File_Now) + "/" + Path.GetFileNameWithoutExtension(File_Now) + Extract_L.SelectedItem, Extract_L.SelectedItem.ToString(), true);
                                    stw.WriteLine(Path.GetDirectoryName(File_Now) + "/" + Path.GetFileNameWithoutExtension(File_Now) + Extract_L.SelectedItem);
                                }
                                else
                                {
                                    Message_T.Text = Path.GetFileNameWithoutExtension(File_Now) + "をエンコードしています...";
                                    await Task.Delay(5);

                                    Sub_Code.Audio_Encode_To_Other(File_Now, Path.GetDirectoryName(File_Now) + "/Temp" + Path.GetFileNameWithoutExtension(File_Now) + Extract_L.SelectedItem, Extract_L.SelectedItem.ToString(), true);
                                    Sub_Code.File_Move(Path.GetDirectoryName(File_Now) + "/Temp" + Path.GetFileNameWithoutExtension(File_Now) + Extract_L.SelectedItem, File_Now, true);
                                    stw.WriteLine(File_Now);
                                }
                            }
                            stw.Close();
                            if (Extract_L.SelectedIndex == 0 || Extract_L.SelectedIndex == 5)
                            {
                                File.Delete(ofd.SelectedFolder + "/" + Path.GetFileNameWithoutExtension(File_Full_Name) + ".tmp");
                            }
                            else
                            {
                                string FromFile = ofd.SelectedFolder + "/" + Path.GetFileNameWithoutExtension(File_Full_Name) + ".tmp";
                                string ToFile   = ofd.SelectedFolder + "/" + Path.GetFileNameWithoutExtension(File_Full_Name) + ".wfs";
                                Sub_Code.File_Encrypt(FromFile, ToFile, "WoTB_FSB_Encode_Save", true);
                            }
                        }
                        else
                        {
                            Message_Feed_Out("抽出できませんでした。");
                            return;
                        }
                    }
                    catch (Exception e1)
                    {
                        Message_Feed_Out("正常に完了しませんでした。");
                        Sub_Code.Error_Log_Write(e1.Message);
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            Message_Feed_Out("抽出しました。");
        }
Beispiel #3
0
        //FSBファイルを選択
        private async void FSB_Select_B_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (IsClosing)
            {
                return;
            }
            System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog()
            {
                Title       = "FSBファイルを選択してください。",
                Filter      = "FSBファイル(*.fsb;*.fsb.dvpl)|*.fsb;*.fsb.dvpl",
                Multiselect = false
            };
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    bool IsDVPL = false;
                    int  Number = 0;
                    if (Path.GetExtension(ofd.FileName) == ".dvpl")
                    {
                        IsDVPL = true;
                        if (!File.Exists(Voice_Set.Special_Path + "/FSB_Select_Temp_01.fsb"))
                        {
                            DVPL.DVPL_UnPack(ofd.FileName, Voice_Set.Special_Path + "/FSB_Select_Temp_01.fsb", false);
                            Number = 1;
                        }
                        else if (!File.Exists(Voice_Set.Special_Path + "/FSB_Select_Temp_02.fsb"))
                        {
                            DVPL.DVPL_UnPack(ofd.FileName, Voice_Set.Special_Path + "/FSB_Select_Temp_02.fsb", false);
                            Number = 2;
                        }
                        else if (!File.Exists(Voice_Set.Special_Path + "/FSB_Select_Temp_03.fsb"))
                        {
                            DVPL.DVPL_UnPack(ofd.FileName, Voice_Set.Special_Path + "/FSB_Select_Temp_03.fsb", false);
                            Number = 3;
                        }
                    }
                    FModChannel.setPaused(true);
                    FModChannel = new FMOD_API.Channel();
                    SubSound.release();
                    MainSound.release();
                    SubSound        = new FMOD_API.Sound();
                    MainSound       = new FMOD_API.Sound();
                    Location_T.Text = "00:00";
                    Message_T.Text  = "FSBファイルを読み込んでいます...";
                    await Task.Delay(50);

                    FSB_Select_T.Text = Path.GetFileName(ofd.FileName);
                    List <string> Name_List;
                    if (IsDVPL)
                    {
                        File_Full_Name = Voice_Set.Special_Path + "/FSB_Select_Temp_0" + Number + ".fsb";
                        Name_List      = Fmod_Class.FSB_GetNames(Voice_Set.Special_Path + "/FSB_Select_Temp_0" + Number + ".fsb");
                    }
                    else
                    {
                        File_Full_Name = ofd.FileName;
                        Name_List      = Fmod_Class.FSB_GetNames(ofd.FileName);
                    }
                    FSB_Number_T.Text = "ファイル数:" + Name_List.Count + " | 選択:なし";
                    FSB_Name_L.Items.Clear();
                    foreach (string Name_Now in Name_List)
                    {
                        FSB_Name_L.Items.Add(Name_Now);
                    }
                    if (Name_List.Count == 0)
                    {
                        Message_Feed_Out("内容を取得できませんでした。");
                    }
                    else
                    {
                        Message_Feed_Out("読み込みが完了しました。");
                    }
                    if (Number == 1)
                    {
                        Sub_Code.File_Delete_V2(Voice_Set.Special_Path + "/FSB_Select_Temp_02.fsb");
                        Sub_Code.File_Delete_V2(Voice_Set.Special_Path + "/FSB_Select_Temp_03.fsb");
                    }
                    else if (Number == 2)
                    {
                        Sub_Code.File_Delete_V2(Voice_Set.Special_Path + "/FSB_Select_Temp_01.fsb");
                        Sub_Code.File_Delete_V2(Voice_Set.Special_Path + "/FSB_Select_Temp_03.fsb");
                    }
                    else if (Number == 3)
                    {
                        Sub_Code.File_Delete_V2(Voice_Set.Special_Path + "/FSB_Select_Temp_01.fsb");
                        Sub_Code.File_Delete_V2(Voice_Set.Special_Path + "/FSB_Select_Temp_02.fsb");
                    }
                }
                catch (Exception e1)
                {
                    Message_Feed_Out("エラー:FSBファイルが壊れている可能性があります。");
                    Sub_Code.Error_Log_Write(e1.Message);
                }
            }
        }