//UserDTO(XML 単純DTO)をFAS(C# コード処理クラス)に変換します public static FileAttributeSet UserSetAttDTOtoFAS(UserSetAttDTO dto) { FileAttributeSet fas = new FileAttributeSet(); fas.AnalysisFormatTYPE = dto.AnalyzType; fas.AttHeader = dto.StartHeaderBytes; fas.EndHeader = dto.EndHeaderBytes; fas.kakutyoushi = dto.kakutyoushi; //エラー解除 fas.ERR = false; return(fas); }
// 拡張子をロードする(ソースコードべた書き定義&XML&Plugin) private void KakutyousiLoad() { COMBkaku.Items.Clear(); FileAttributeSet FAS = new FileAttributeSet(); COMBkaku.Items.AddRange(FAS.printAttribute()); // ユーザーリスト拡張子読み込み usaList = UserListForm.UserXmlLoad(UserListForm.defaultfilename); COMBkaku.Items.AddRange(UserListForm.UserSetAttDTONameList(usaList)); //プラグイン用拡張子 COMBkaku.Items.AddRange(PluginWorkKakutyoushi()); }
private void EXECUT() { int BaseBaffuer = Convert.ToInt32(TBBlockBuff.Text); bool INDEXCREATE = false; bool EXECUTE = true;//デフォはtrue int WorkedFileCount = 0; // プラグイン処理かを判定するのに使うフラグ bool PluginExeFlag = false; // プラグインの配列指定 int PluginArgMentNumber = 0; FileAttributeSet FAS = new FileAttributeSet(); FAS.SetHeader(SelectKakutyousi); //もしFASでエラーが発生した場合ユーザー定義拡張子の可能性があるのでそっちを探す if (FAS.ERR == true) { //FASの再構築 foreach (UserSetAttDTO al in usaList) { if (SelectKakutyousi == al.name) { FAS = UserSetAttDTO.UserSetAttDTOtoFAS(al); } } } // プラグインの検索を行う if (FAS.ERR == true) { foreach (String pl in PluginNameAndKaku) { if (SelectKakutyousi == pl) { PluginExeFlag = true; } } } // FASの再構築も、プラグインの検索も失敗したらエラー if (FAS.ERR == true && PluginExeFlag == false) { MessageBox.Show("選択した拡張子セット設定が不正か見つかりません。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (CBSymrate.Checked == true) { EXECUTE = false; } WARKING = true; int Start = Environment.TickCount; int RenbanKeta = (int)NuupKETA.Value; string filename = TBtarget.Text; string CreateFileBaseName = TBCBN.Text; string BaseDirectory = TBsyutu.Text; // プラグインを使用しない抽出の時 if (PluginExeFlag == false) { DataCutter DC = new DataCutter(); WorkedFileCount = DC._cutter(filename, FAS, BaseBaffuer, EXECUTE, INDEXCREATE, CreateFileBaseName, BaseDirectory, RenbanKeta, TBDBlog); } else { String [] kakutyoushiAR = SelectKakutyousi.Split(new Char[] { ':' }); String kakutyoushi = kakutyoushiAR[kakutyoushiAR.Length - 1]; String[] PluginNameAr = kakutyoushiAR[0].Split(new char[] { ' ' }); String pluginname = PluginNameAr[PluginNameAr.Length - 1]; int ifx = 0; foreach (DataCutter_PlugIn.PluginInterface pl in plugins) { if (pl.Pluginame == pluginname) { PluginArgMentNumber = ifx; } ifx++; } // プラグインを使用する抽出の時 /* * // PLUGIN TYPE <Normal> 処理したファイル数を返します * int _cutter( * bool Exe, * bool IndexFileCreate, * int buffer_Level, * int RenbanKeta, * string filename, * string kakutyoushi, * string CreateFileBaseName, * string BaseDirectory, * TextBox DebugTB * );*/ WorkedFileCount = plugins[PluginArgMentNumber]._cutter( EXECUTE, INDEXCREATE, BaseBaffuer, RenbanKeta, filename, kakutyoushi, CreateFileBaseName, BaseDirectory, TBDBlog ); } int END = Environment.TickCount; string apt = String.Format("抽出数 {0} /:BaseBuff {1}\r\n", WorkedFileCount, BaseBaffuer); TBDBlog.AppendText(apt); TBDBlog.AppendText(String.Format("処理時間: {0} ミリ秒\r\n", END - Start)); TBDBlog.AppendText("処理完了しました\r\n"); WARKING = false; }
//bool Exe=trueで実行、falseでシミュレートのみ // buffer_Level はwmvのときは4096でOk /*各拡張子に対応できるよう汎用性をもたせる * ユーザーがサーチバイトを指定できるようにする * ArraySerchとして別に汎用関数を書いてライブラリDLL化しとく * CFN生成の ディレクトリ指定できるように、ディレクトリがない場合作成 * 何枚ファイルを生成するかも引数にする * 返り値=cutできた/cutできるファイル数 */ public int _cutter( string filename, FileAttributeSet FAS, int buffer_Level, bool Exe, bool IndexFileCreate, string CreateFileBaseName, string BaseDirectory, int RenbanKeta, TextBox DebugTB) { if (CreateFileBaseName == null) { CreateFileBaseName = filename + "cut"; } //ディレクトリが存在するかしなかのチェックは外部でする if (BaseDirectory != null) { // CreateFileBaseName=BaseDirectory+"\\"+CreateFileBaseName; CreateFileBaseName = BaseDirectory + CreateFileBaseName; //GUI側で+\\しとく } //連番ファイルstring構築 string stRebnan = Convert.ToString(RenbanKeta); stRebnan = "d" + stRebnan; StreamWriter SWidx = null; string stidxs; if (IndexFileCreate == true) { //インデックスファイル名はfilename+"拡張子"+".idx" FileStream FSidx = new FileStream(filename + "_" + FAS.kakutyoushi + ".idx", FileMode.Create, FileAccess.Write); SWidx = new StreamWriter(FSidx); SWidx.WriteLine("FileNo,BlockNo,KITEN,Filesize"); } int SBIdx = 0; int ReturnInt = 0; int COUNT = buffer_Level; //4096=デフォルト FileStream sr = new FileStream(filename, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(sr); byte [] buffer = new byte[COUNT]; bool flag, WriteOK = true; int ix, BlockNO = 1, KITEN, beforeKITEN = 0, cFiles, FileNO = 0, ESBIdx = 0; string CuttingFileName = null; FileStream CFN = null; BinaryWriter CFNBR = null; int [] KITENS; //生成ファイル名は filename+"cut"+FileNO+".拡張子" if (Exe == true) { CuttingFileName = String.Format("{0}{1:" + stRebnan + "}{2}", CreateFileBaseName, FileNO, FAS.kakutyoushi); CFN = new FileStream(CuttingFileName, FileMode.Create, FileAccess.Write); CFNBR = new BinaryWriter(CFN); } if (FAS.AnalysisFormatTYPE == 0) { /*文字列照合アルゴリズムかkuth/Boyer使ったほうが速い*/ for (int idx = 0; idx < sr.Length; idx += COUNT) { br.Read(buffer, 0, COUNT); //---------- バッファBlockサーチ処理ルーチン //ブロックの末尾にサーチ対象がある場合もルーチンが必要 BlockNO++; ix = 0; while (ix < COUNT) { flag = false; //trueになるまで書き込み+調査 while (flag == false) { //writeバッファはためこんで8096単位で書き込み //このままだと完成ファイルの末尾にゴミヘッダがつく if (Exe == true && WriteOK == true) { CFNBR.Write(buffer[ix]); } if (buffer[ix] == FAS.AttHeader[SBIdx]) { SBIdx++; if (SBIdx == FAS.AttHeader.Length) { flag = true; SBIdx = 0; } } else { SBIdx = 0; } if (FAS.EndHeader != null && buffer[ix] == FAS.EndHeader[ESBIdx]) { ESBIdx++; if (ESBIdx == FAS.EndHeader.Length) { WriteOK = false; ESBIdx = 0; } } else { ESBIdx = 0; } ix++; if (ix >= COUNT) { break; } } if (flag == true) { ReturnInt++; KITEN = idx + ix - FAS.AttHeader.Length + 1; //+1は配列[0]のため cFiles = KITEN - beforeKITEN; //EndHederの時は別処理 beforeKITEN = KITEN; if (IndexFileCreate == true) { stidxs = String.Format("{0},{1},{2},{3}\n", ReturnInt, BlockNO, KITEN, cFiles); SWidx.Write(stidxs); } if (DebugTB != null) { //stidxs=String.Format("{0} {1} {2}\r\n",ReturnInt,BlockNO,KITEN); //なんかtextboxエラーでるので stidxs = String.Format("{0}\r\n", ReturnInt); DebugTB.AppendText(stidxs); } if (Exe == true) { // CFNBR.Write(buffer); CFNBR.Flush(); CFNBR.Close(); CFN.Close(); FileNO++; Console.WriteLine(FileNO); //1ブロックに複数ファイルがあるときのルーチンが必要[clear!] CuttingFileName = String.Format("{0}{1:" + stRebnan + "}{2}", CreateFileBaseName, FileNO, FAS.kakutyoushi); CFN = new FileStream(CuttingFileName, FileMode.Create, FileAccess.Write); CFNBR = new BinaryWriter(CFN); CFNBR.Write(FAS.AttHeader); //ヘッダの書き込み WriteOK = true; // CFNBR.Write(buffer,ix-SearchBytes.Length,buffer.Length-(ix-SearchBytes.Length)); } } // SBIdx=0;//削除すれば下段ブロック処理になる[clear!] } // if(Exe == true && FirstWrited == false){CFNBR.Write(buffer);} } } //if(FAS.AnalysisFormatTYPE == 0) //WAV&RIFF/AVI用 else if (FAS.AnalysisFormatTYPE == 1) { BlockNO = 0; //1になってるので0に初期化 int KadanPosition = 0, FindCount = 0, sw, oneWrite, sSize = 0; uint Size = 0; WriteOK = false; byte [] Size4byte = new byte[4]; for (int idx = 0; idx < sr.Length; idx += COUNT) { br.Read(buffer, 0, COUNT); KITENS = SimpleArraySearchS(buffer, FAS.AttHeader, 0, ref KadanPosition , ref FindCount); if (KITENS[0] != -1) { for (int ic = 0; ic < FindCount; ic++) { ReturnInt++; Console.WriteLine("block {0} ,\t bk{1},KITEN{2}", BlockNO, KITENS[ic], (BlockNO * COUNT) + KITENS[ic]); sw = KITENS[ic]; Size = 8 + ReverceEdian(buffer[sw + 4], buffer[sw + 5], buffer[sw + 6], buffer[sw + 7]); Console.WriteLine("@ {0:x2}{1:x2}{2:x2}{3:x2} SIZE={4}+8", buffer[sw + 4], buffer[sw + 5], buffer[sw + 6], buffer[sw + 7], Size); if (Exe == true) { if (WriteOK == true) { CFNBR.Write(buffer, 0, KITENS[ic]); } CFNBR.Flush(); CFNBR.Close(); CFN.Close(); FileNO++; Console.WriteLine("FileCreate{0}", FileNO); CuttingFileName = String.Format("{0}{1:" + stRebnan + "}{2}", CreateFileBaseName, FileNO, FAS.kakutyoushi); CFN = new FileStream(CuttingFileName, FileMode.Create, FileAccess.Write); CFNBR = new BinaryWriter(CFN); CFNBR.Write(buffer, KITENS[ic], buffer.Length - KITENS[ic]); sSize = (int)Size; sSize -= buffer.Length - KITENS[ic]; WriteOK = true; } } } else { if (Exe == true && WriteOK == true) { if (sSize < buffer.Length) { //oneWrite=sSize; CFNBR.Write(buffer, 0, sSize); //CFNBR.Write(buffer,0,sSize+8);//?暫定 WriteOK = false; } else { sSize -= buffer.Length; CFNBR.Write(buffer); } } } BlockNO++; } // if(Exe == true){CFN.Close();} } if (Exe == true) { CFNBR.Flush(); CFNBR.Close(); //00fileを削除(暫定) File.Delete(String.Format("{0}{1:" + stRebnan + "}{2}", CreateFileBaseName, 0, FAS.kakutyoushi)); } br.Close(); sr.Close(); if (IndexFileCreate == true) { SWidx.Flush(); SWidx.Close(); } return(ReturnInt); } //_cut