public static void ZipsDumpTAHEntries(ArcsDatabase db, string zipname) { string ext = Path.GetExtension(zipname).ToLower(); if (ext == ".zip" || ext == ".lzh" || ext == ".rar") { TDCGExplorer.SetToolTips("Processing " + Path.GetFileName(zipname)); Regex filter = new Regex(zipcoderegexp); Match match = filter.Match(Path.GetFileName(zipname)); if (match.Success) { DateTime datetime = File.GetLastWriteTime(zipname); ArcsZipArcEntry entry = new ArcsZipArcEntry(); entry.id = 0; entry.path = zipname.Substring(zipspath.Length + 1); entry.code = match.Groups[1].ToString(); entry.exist = 1; entry.datetime = datetime; entry.id = db.SetZipEntry(entry); ZipDumpArcEntries(db, entry); } else { DateTime datetime = File.GetLastWriteTime(zipname); ArcsZipArcEntry entry = new ArcsZipArcEntry(); entry.id = 0; entry.path = zipname.Substring(zipspath.Length + 1); entry.code = Path.GetFileNameWithoutExtension(zipname); entry.exist = 1; entry.datetime = datetime; entry.id = db.SetZipEntry(entry); ZipDumpArcEntries(db, entry); } } }
public CollisionTahPageControl(CollisionItem argCollisionEntry) { InitializeComponent(); collisionEntry = argCollisionEntry; Text = Path.GetFileName(collisionEntry.tah.path); TDCGExplorer.TDCGExplorer.SetToolTips(Text); DataTable data = new DataTable(); data.Columns.Add(TextResource.CollisionFrom, Type.GetType("System.String")); data.Columns.Add(TextResource.CollisionTo, Type.GetType("System.String")); data.Columns.Add(TextResource.CollisionedTAH, Type.GetType("System.String")); foreach (ArcsCollisionRecord col in collisionEntry.entries) { ArcsDatabase db = TDCGExplorer.TDCGExplorer.ArcsDB; // 衝突した先のtahを取得する. ArcsTahEntry to = db.GetTah(col.toTahID); // 既に同じ名前で追加していないか調べる. ArcsTahFilesEntry fromfile = db.GetTahFilesEntry(col.fromFilesID); ArcsTahFilesEntry tofile = db.GetTahFilesEntry(col.toFilesID); DataRow row = data.NewRow(); string[] content = { fromfile.GetDisplayPath(), tofile.GetDisplayPath().ToLower(), to.shortname }; row.ItemArray = content; data.Rows.Add(row); } dataGridView.DataSource = data; dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; dataGridView.ReadOnly = true; dataGridView.AllowUserToAddRows = false; dataGridView.AllowUserToDeleteRows = false; selectIndex(0); }
public static void ZipDumpArcEntries(ArcsDatabase db, ArcsZipArcEntry entry) { string ext = Path.GetExtension(entry.path).ToLower(); switch (ext) { case ".zip": using (IArchive arc = new ZipArchive()) { DumpArcEntries(db, Path.Combine(TDCGExplorer.SystemDB.zips_path, entry.path), arc, entry.id); } break; case ".rar": using (IArchive arc = new RarArchive()) { DumpArcEntries(db, Path.Combine(TDCGExplorer.SystemDB.zips_path, entry.path), arc, entry.id); } break; case ".lzh": using (IArchive arc = new LzhArchive()) { DumpArcEntries(db, Path.Combine(TDCGExplorer.SystemDB.zips_path, entry.path), arc, entry.id); } break; default: break; } }
public static void ArcsDumpTahFilesEntries(ArcsDatabase db, ArcsTahEntry entry, TAHFile tah) { string source = Path.Combine(TDCGExplorer.SystemDB.arcs_path, entry.path); int tahentry = 0; foreach (TAHEntry ent in tah.EntrySet.Entries) { if (ent.FileName == null) { TDCGExplorer.SetToolTips("Dump " + ent.Hash.ToString("x8") + " file"); } else { TDCGExplorer.SetToolTips("Dump " + ent.FileName + " file"); } ArcsTahFilesEntry fileentry = new ArcsTahFilesEntry(); fileentry.id = 0; fileentry.tahid = entry.id; fileentry.tahentry = tahentry++; fileentry.path = ent.FileName; if (entry.path == null) { entry.path = ""; } fileentry.hash = (int)ent.Hash; fileentry.length = (int)ent.Length; db.SetTahFilesPath(fileentry); } }
private void selectIndex(int index) { ArcsCollisionRecord col = collisionEntry.entries[index]; ArcsDatabase db = TDCGExplorer.TDCGExplorer.ArcsDB; // 衝突した先のtahを取得する. ArcsTahEntry from = db.GetTah(col.fromTahID); ArcsTahEntry to = db.GetTah(col.toTahID); // 既に同じ名前で追加していないか調べる. ArcsTahFilesEntry fromfile = db.GetTahFilesEntry(col.fromFilesID); ArcsTahFilesEntry tofile = db.GetTahFilesEntry(col.toFilesID); string text = @"<p>" + @"<h2> " + TextResource.CollisionHTML_CollisionFrom + " : " + from.shortname + "</h2>" + @"<adress>" + TextResource.Directory + " : " + Path.GetDirectoryName(from.path) + "</adress>" + @"<h3> " + TextResource.CollisionHTML_CollisionTo + " : " + to.shortname + "</h3>" + @"<adress>" + TextResource.Directory + " : " + Path.GetDirectoryName(to.path) + "</adress>" + @"<pre>" + fromfile.GetDisplayPath().ToLower() + " --> " + tofile.GetDisplayPath().ToLower() + "</pre>" + @"<pre>" + TextResource.HashCode + " : " + tofile.hash.ToString("x8") + "</pre>"; webBrowser.DocumentText = text; try { string filename = fromfile.GetDisplayPath().ToLower(); if (Path.GetExtension(filename) == ".tso") { // TSOを表示する. using (GenericTAHStream tahstream = new GenericTAHStream(new GenericArcsTahInfo(from), fromfile)) { Cursor.Current = Cursors.WaitCursor; TDCGExplorer.TDCGExplorer.MainFormWindow.makeTSOViwer(); TDCGExplorer.TDCGExplorer.MainFormWindow.clearTSOViewer(); TDCGExplorer.TDCGExplorer.MainFormWindow.Viewer.LoadTSOFile(tahstream.stream); if (TDCGExplorer.TDCGExplorer.SystemDB.loadinitialpose) { TDCGExplorer.TDCGExplorer.MainFormWindow.doInitialTmoLoad(); // 初期tmoを読み込む. } // カメラをセンター位置に. TSOCameraAutoCenter camera = new TSOCameraAutoCenter(TDCGExplorer.TDCGExplorer.MainFormWindow.Viewer); camera.UpdateCenterPosition(fromfile.path.ToUpper()); // 次回カメラが必ずリセットされる様にする. TDCGExplorer.TDCGExplorer.MainFormWindow.setNeedCameraReset(); Cursor.Current = Cursors.Default; //TDCGExplorer.TDCGExplorer.FigureLoad = false; } } } catch (Exception) { } }
private void toolStripMenuItemEditTah_Click(object sender, EventArgs e) { if (TDCGExplorer.TDCGExplorer.BusyTest() == true) { return; } ArcsCollisionRecord col = collisionEntry.entries[0]; ArcsDatabase db = TDCGExplorer.TDCGExplorer.ArcsDB; ArcsTahEntry from = db.GetTah(col.fromTahID); LBFileTahUtl.OpenTahEditor(new GenericArcsTahInfo(from)); }
public static void ArcsDumpDirEntries(string dir, ArcsDatabase db) { bool skipflag = false; string[] shortnames = dir.Split('\\'); foreach (string shortname in shortnames) { if (shortname[0] == '!') { skipflag = true; } } if (skipflag) { return; // !で始まるディレクトリはスキップ } string[] tah_files = Directory.GetFiles(dir, "*.TAH"); foreach (string file in tah_files) { // 既にdb上にエントリがあるか調べる. //string tahid = db.GetTahID(file.Substring(arcspath.Length + 1)); ArcsTahEntry tah = db.GetTah(file.Substring(arcspath.Length + 1)); if (tah != null) { // 日付が一致するか? DateTime datetime = File.GetLastWriteTime(file); if (tah.datetime.ToString() == datetime.ToString()) { // 該当するエントリの存在フラグを立てる. TDCGExplorer.SetToolTips("Update " + Path.GetFileName(file)); db.UpdateTahExistUp(tah.id); continue; } else { // dbから一旦削除する. db.DeleteTah(tah.id); } } TDCGExplorer.LastAccessFile = file; using (FileStream source = File.OpenRead(file)) { ArcsDumpTAHEntries(source, db, file); } } string[] entries = Directory.GetDirectories(dir); foreach (string entry in entries) { ArcsDumpDirEntries(entry, db); } }
public static void ArcsDumpDirEntriesMain(string dir, ArcsDatabase db) { arcspath = dir; if (Directory.Exists(dir) == true) { // 存在フラグを全て落とす. TDCGExplorer.SetToolTips("Setup database"); db.UpdateTahExistDown(); ArcsDumpDirEntries(dir, db); // 存在しないtahファイルは消去する. TDCGExplorer.SetToolTips("Deleting orphan records"); db.DeleteNoExistentTah(); } }
//ファイルシステムをスキャンしてZIP情報を集める. public static void ZipsDumpDirEntriesMain(string dir, ArcsDatabase db) { zipspath = dir; if (Directory.Exists(dir) == true) { zipcoderegexp = TDCGExplorer.SystemDB.zip_regexp; // 存在フラグを全て落とす. TDCGExplorer.SetToolTips("Setup database"); db.UpdateZipExistDown(); ZipsDumpDirEntries(dir, db); // 存在しないtahファイルは消去する. TDCGExplorer.SetToolTips("Deleting orphan records"); db.DeleteNoExistentZip(); } }
public static void ArcsDumpTAHEntries(Stream source, ArcsDatabase db, string tahname) { try { TDCGExplorer.SetToolTips("Processing " + Path.GetFileName(tahname)); using (TAHFile tah = new TAHFile(source)) { try { tah.LoadEntries(); } catch (Exception ex) { Debug.WriteLine("Error: " + ex); return; } DateTime datetime = File.GetLastWriteTime(tahname); ArcsTahEntry entry = new ArcsTahEntry(); entry.path = tahname.Substring(arcspath.Length + 1); entry.shortname = Path.GetFileName(tahname).ToLower(); entry.version = (int)tah.Header.Version; entry.id = 0; entry.exist = 1; entry.datetime = datetime; entry.id = db.SetTahEntry(entry); ArcsDumpTahFilesEntries(db, entry, tah); } } catch (Exception ex) { Debug.WriteLine("Error: " + ex); return; } }
public void Run() { TDCGExplorer.TDCGExplorer.IncBusy(); ArcsDatabase arcDB = TDCGExplorer.TDCGExplorer.ArcsDB; // TAHを列挙する. List <ArcsTahEntry> tahs = arcDB.GetTahs(); foreach (ArcsTahEntry tah in tahs) { Dictionary <string, ArcsTahEntry> tbnmap = new Dictionary <string, ArcsTahEntry>(); List <ArcsTahFilesEntry> files = arcDB.GetTahFilesPath(tah.id); foreach (ArcsTahFilesEntry file in files) { try { TDCGExplorer.TDCGExplorer.SetToolTips(TextResource.Searching + ":" + tah.shortname); if (file.path.ToLower().StartsWith("script/items/") /*|| file.path.ToLower().StartsWith("script/backgrounds/" )*/) { // TBNファイルか? if (file.path.ToLower().EndsWith(".tbn") == true) { // N765BODY_A00.TBN // 1234567890123456 string directory = Path.GetDirectoryName(file.path).ToLower().Replace('\\', '/'); string fullname = Path.GetFileNameWithoutExtension(file.path).ToLower(); string basename = fullname.Substring(0, 10); string colbase = directory + "/" + basename + "00.tbn"; // <<1.08.1 // コード毎のtbnファイル名を全て集める. if (tbnfiles.ContainsKey(colbase) == false) { tbnfiles.Add(colbase, new List <string>()); } tbnfiles[colbase].Add(file.path); // 1.08.1>> if (tbnmap.ContainsKey(colbase) == true) { continue; // 既に該当tbnの情報を見つけている. } // baseとなるtbnそのものだった場合. if (file.path.ToLower() == colbase) { tbnmap.Add(colbase, tah); continue; } // カテゴリ先頭のtbnファイルを検索する. List <ArcsTahFilesEntry> tbns = arcDB.GetTahFilesEntry(TDCGExplorer.TAHUtil.CalcHash(colbase)); if (tbns.Count == 0) { // 該当するtbnの00番が見つからない. MissingEntryInformation entry = new MissingEntryInformation(); entry.id = tah.id; entry.path = String.Copy(tah.path); entry.basetbn = String.Copy(colbase); entry.zipfiles = null; // 該当tbnを含むzipを検索する. HashSet <string> zipname = new HashSet <string>(); List <ArcsTahFilesEntry> zipfiles = arcDB.GetZipTahFilesEntries(TDCGExplorer.TAHUtil.CalcHash(colbase)); foreach (ArcsTahFilesEntry zipfile in zipfiles) { if (zipfile.path.ToLower() != colbase) { continue; // ハッシュ衝突なら無視する. } ArcsZipTahEntry ziptah = arcDB.GetZipTah(zipfile.tahid); ArcsZipArcEntry zip = arcDB.GetZip(ziptah.zipid); zipname.Add(zip.GetDisplayPath()); } // 発見したZIPの数だけ報告する.0 if (zipname.Count == 0) { control.asyncDisplayFromArcs(entry); } else { entry.zipfiles = new List <string>(); foreach (string zip in zipname) { entry.zipfiles.Add(String.Copy(zip)); } control.asyncDisplayFromArcs(entry); } } tbnmap.Add(colbase, tah); } } } // おかしなファイル名でindex違反が起きるかもしれない. catch (Exception) { } } } // TBN辞書をセットして終了 control.tbnfiles = tbnfiles; TDCGExplorer.TDCGExplorer.SetToolTips(TextResource.SearchComplete); TDCGExplorer.TDCGExplorer.DecBusy(); }
public static void DumpArcEntries(ArcsDatabase db, string source_file, IArchive arc, int id) { try { TDCGExplorer.LastAccessFile = source_file; arc.Open(source_file); foreach (IArchiveEntry entry in arc) { // ディレクトリのみの場合はスキップする. if (entry.IsDirectory == true) { continue; } // TAHファイルなら詳細をダンプする. if (Path.GetExtension(entry.FileName) == ".tah") { using (MemoryStream ms = new MemoryStream((int)entry.Size)) { arc.Extract(entry, ms); ms.Seek(0, SeekOrigin.Begin); using (TAHFile tah = new TAHFile(ms)) { try { tah.LoadEntries(); } catch (Exception ex) { Debug.WriteLine("Error: " + ex); continue; } ArcsZipTahEntry ziptahentry = new ArcsZipTahEntry(); ziptahentry.id = 0; ziptahentry.path = entry.FileName; ziptahentry.shortname = Path.GetFileName(entry.FileName).ToLower(); ziptahentry.version = (int)tah.Header.Version; ziptahentry.zipid = id; int tahid = db.SetZipTahEntry(ziptahentry); int tahentry = 0; foreach (TAHEntry ent in tah.EntrySet.Entries) { if (ent.FileName == null) { TDCGExplorer.SetToolTips("Dump " + ent.Hash.ToString("x8") + " file"); } else { TDCGExplorer.SetToolTips("Dump " + Path.GetFileName(ent.FileName) + " file"); } ArcsTahFilesEntry fileentry = new ArcsTahFilesEntry(); fileentry.id = 0; fileentry.tahid = tahid; fileentry.tahentry = tahentry++; fileentry.path = ent.FileName; if (fileentry.path == null) { fileentry.path = ""; } //fileentry.md5sum = ""; fileentry.hash = (int)ent.Hash; fileentry.length = (int)ent.Length; db.SetZipTahFilesPath(fileentry); } } } } else { // tahファイル以外はファイル名のみ情報を格納する. ArcsZipTahEntry ziptahentry = new ArcsZipTahEntry(); ziptahentry.id = 0; ziptahentry.path = entry.FileName; ziptahentry.version = 0; ziptahentry.zipid = id; int tahid = db.SetZipTahEntry(ziptahentry); } } } catch (Exception ex) { Debug.WriteLine("Error: " + ex); return; } }
public static void ZipsDumpDirEntries(string dir, ArcsDatabase db) { // ファイルを思わしき者は全部調べて、その中からzip,lzh,rarを抽出する. string[] zip_files = Directory.GetFiles(dir, "*.*"); foreach (string file in zip_files) { //string zipid = db.GetZipID(file.Substring(zipspath.Length + 1)); ArcsZipArcEntry zip = db.GetZip(file.Substring(zipspath.Length + 1)); if (zip != null) { DateTime datetime = File.GetLastWriteTime(file); if (zip.datetime.ToString() == datetime.ToString()) { // 該当するエントリの存在フラグを立てる. TDCGExplorer.SetToolTips("Update " + Path.GetFileName(file)); db.UpdateZipExistUp(zip.id); continue; } else { db.DeleteZip(zip.id); } } ZipsDumpTAHEntries(db, file); } string[] entries = Directory.GetDirectories(dir); foreach (string entry in entries) { // 解凍済みMODを処理する. string zipname = entry.Substring(zipspath.Length + 1); ArcsZipArcEntry zip = db.GetZip(zipname); if (zip != null) { DateTime datetime = File.GetLastWriteTime(entry); if (zip.datetime.ToString() == datetime.ToString()) { // 該当するエントリの存在フラグを立てる. TDCGExplorer.SetToolTips("Update " + Path.GetFileName(zip.path)); db.UpdateZipExistUp(zip.id); continue; } } // MOD名に一致するか調べる. char[] separetor = { '\\', '/' }; string[] sublevel = zipname.Split(separetor); string directory = sublevel[sublevel.Length - 1]; Regex regDirectAccess = new System.Text.RegularExpressions.Regex(TDCGExplorer.SystemDB.directaccess_signature); Match m = regDirectAccess.Match(directory); if (m.Success) { Regex filter = new Regex(zipcoderegexp); Match match = filter.Match(directory); if (match.Success == true) { TDCGExplorer.SetToolTips("Processing " + directory); ArcsZipArcEntry ent = new ArcsZipArcEntry(); ent.id = 0; ent.path = zipname; ent.code = match.Groups[1].ToString(); ent.exist = 1; ent.datetime = File.GetLastWriteTime(entry); ent.id = db.SetZipEntry(ent); DumpArcEntries(db, entry, new DirectAccessArchive(), ent.id); continue; } } // 通常のディレクトリスキャン. ZipsDumpDirEntries(entry, db); } }
public void Run() { TDCGExplorer.TDCGExplorer.IncBusy(); ArcsDatabase arcDB = TDCGExplorer.TDCGExplorer.ArcsDB; // TAHを列挙する. List <ArcsTahEntry> tahs = arcDB.GetTahs(); foreach (ArcsTahEntry tah in tahs) { TDCGExplorer.TDCGExplorer.SetToolTips("検索中:" + tah.shortname); if (HasString(tah.path, keyword)) { FindEntryInformation entry = new FindEntryInformation(); entry.category = 0; // arcs entry.path = String.Copy(tah.path); entry.file = Path.GetFileName(tah.path); control.asyncDisplayFromArcs(entry); } } if (flagtahlevelsearch) { List <ArcsTahFilesEntry> files = arcDB.GetTahFilesPathHasString(keyword); foreach (ArcsTahFilesEntry file in files) { ArcsTahEntry tah = arcDB.GetTah(file.tahid); FindEntryInformation entry = new FindEntryInformation(); entry.category = 0; // arcs entry.path = String.Copy(tah.path); entry.file = String.Copy(file.GetDisplayPath()); control.asyncDisplayFromArcs(entry); } } if (flagzipsearch) { List <ArcsZipArcEntry> zips = arcDB.GetZips(); foreach (ArcsZipArcEntry zip in zips) { TDCGExplorer.TDCGExplorer.SetToolTips(TextResource.Searching + ":" + zip.GetDisplayPath()); if (HasString(zip.GetDisplayPath(), keyword)) { FindEntryInformation entry = new FindEntryInformation(); entry.category = 1; //zips entry.path = String.Copy(Path.GetDirectoryName(zip.path) + "\\" + zip.GetDisplayPath()); entry.file = zip.GetDisplayPath(); control.asyncDisplayFromArcs(entry); } } // LIKE文で総当たりする. List <ArcsZipTahEntry> ziptahs = arcDB.GetZipTahsHasString(keyword); foreach (ArcsZipTahEntry tah in ziptahs) { ArcsZipArcEntry subzip = arcDB.GetZip(tah.zipid); FindEntryInformation entry = new FindEntryInformation(); entry.category = 1; //zips entry.path = String.Copy(Path.GetDirectoryName(subzip.path) + "\\" + subzip.GetDisplayPath()); entry.file = tah.shortname; control.asyncDisplayFromArcs(entry); } } if (flagzipsearch && flagtahlevelsearch) { List <ArcsTahFilesEntry> files = arcDB.GetTahFilesPathHasString(keyword); foreach (ArcsTahFilesEntry file in files) { ArcsZipTahEntry tah = arcDB.GetZipTah(file.tahid); ArcsZipArcEntry zip = arcDB.GetZip(tah.zipid); FindEntryInformation entry = new FindEntryInformation(); entry.category = 1; //zips entry.path = String.Copy(zip.path + "\\" + zip.GetDisplayPath()); entry.file = String.Copy(file.GetDisplayPath()); control.asyncDisplayFromArcs(entry); } } // TBN辞書をセットして終了 TDCGExplorer.TDCGExplorer.SetToolTips(TextResource.SearchComplete); TDCGExplorer.TDCGExplorer.DecBusy(); }