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 listBoxMainListBox_SelectedIndexChanged(object sender, EventArgs e) { if (TDCGExplorer.BusyTest()==true) return; try { int index = listBoxMainListBox.SelectedIndex; if (index >= 0) { if (index == lastSelectedListBoxIndex) return; lastSelectedListBoxIndex = index; LbGenItem item = listBoxMainListBox.Items[index] as LbGenItem; if (item != null) { item.DoClick(); listBoxMainListBox.Focus(); } } } catch (Exception exception) { TDCGExplorer.SetToolTips(TextResource.Error + ":" + exception.Message); Debug.WriteLine(exception.Message); } }
public static bool DownloadFile(string uri, string localfile) { try { HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest; SetRequestHeaders(request); HttpWebResponse response = request.GetResponse() as HttpWebResponse; Stream dataStream = response.GetResponseStream(); //File.Delete(localfile); TDCGExplorer.FileDelete(localfile); Stream fileStream = File.Create(localfile); BufferedStream bufferedDataStream = new BufferedStream(dataStream); BufferedStream bufferedFileStream = new BufferedStream(fileStream); byte[] buf = new byte[1024]; int len; while ((len = bufferedDataStream.Read(buf, 0, buf.Length)) > 0) { bufferedFileStream.Write(buf, 0, len); } bufferedFileStream.Flush(); bufferedFileStream.Close(); bufferedDataStream.Close(); response.Close(); return(true); } catch (Exception e) { TDCGExplorer.SetToolTips("Error DownloadFile : " + e.Message); } return(false); }
// ZIPファイルを展開する private void extractZipToolStripMenuItem_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; try { GenericZipTreeNode node = (GenericZipTreeNode)lastSelectTreeNode; if (TDCGExplorer.InstallZipFile(node)) { MessageBox.Show(TextResource.ExtractSuccess, TextResource.ExtractSuccessCaption, MessageBoxButtons.OK); } else { MessageBox.Show(TextResource.ExtractFailure,TextResource.ExtractFailureCaption, MessageBoxButtons.OK); } } catch (System.InvalidCastException ex) { MessageBox.Show(TextResource.ZipFileOnly, TextResource.Error, MessageBoxButtons.OK); Debug.WriteLine(ex.Message); } catch (Exception exception) { TDCGExplorer.SetToolTips(TextResource.Error+ ":" + exception.Message); Debug.WriteLine(exception.Message); } Cursor.Current = Cursors.Default; }
public void SetBitmap(Bitmap bitmap) { if (PictureBox.Image != null) { PictureBox.Image.Dispose(); PictureBox.Image = null; } #if false PictureBox.Image = new Bitmap(bitmap); PictureBox.Width = bitmap.Width; PictureBox.Height = bitmap.Height; #endif try { // 全部読み出す. using (MemoryStream basebmp = new MemoryStream()) { bitmap.Save(basebmp, System.Drawing.Imaging.ImageFormat.Bmp); Bitmap newbmp = new Bitmap(basebmp); PictureBox.Image = (Image)newbmp; PictureBox.Width = newbmp.Width; PictureBox.Height = newbmp.Height; } } catch (Exception e) { Bitmap noimage = new Bitmap(1, 1); PictureBox.Image = noimage; PictureBox.Width = 0; PictureBox.Height = 0; ; TDCGExplorer.SetToolTips("error: " + e.Message); } }
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); } } }
// ツリーを展開する. private void expandAllToolStripMenuItem1_Click(object sender, EventArgs e) { try { TreeNode node = (TreeNode)lastSelectTreeNode; node.ExpandAll(); } catch (Exception exception) { TDCGExplorer.SetToolTips("error:" + exception.Message); Debug.WriteLine(exception.Message); } }
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(); } }
// tagnames.zipをサーバからダウンロードする. public bool DownloadTagNamesZipFromServer() { bool status = false; try { string uri = TDCGExplorer.SystemDB.tagnames_server; string localfile = zipTagLocalName(); // サーバからダウンロードする. HttpUtil.DownloadFile(uri, localfile); status = true; } catch (Exception e) { TDCGExplorer.SetToolTips("Error DownloadTagNamesZipFromServer : " + e.Message); } return(status); }
// アノテーションを編集. private void EditAnnotationToolStripMenuItem_Click(object sender, EventArgs e) { try { GenericZipTreeNode node = lastSelectTreeNode as GenericZipTreeNode; if (node != null) { node.DoEditAnnotation(); } else { MessageBox.Show(TextResource.ZipFileOnly,TextResource.Error, MessageBoxButtons.OK); } } catch (Exception exception) { TDCGExplorer.SetToolTips("error:" + exception.Message); Debug.WriteLine(exception.Message); } }
// 前提zipファイルを展開する. private void ExtractPreferZipToolStripMenuItem_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; try { GenericZipTreeNode node = lastSelectTreeNode as GenericZipTreeNode; if (node != null) { TDCGExplorer.InstallPreferZip(node); } else { MessageBox.Show(TextResource.ZipFileOnly, TextResource.Error, MessageBoxButtons.OK); } } catch (Exception exception) { TDCGExplorer.SetToolTips("error:" + exception.Message); Debug.WriteLine(exception.Message); } Cursor.Current = Cursors.Default; }
private void OpenAllTAHToolStripMenuItem_Click(object sender, EventArgs e) { try { GenericFilesTreeNode node = lastSelectTreeNode as GenericFilesTreeNode; if (node != null) { //node.DoEditAnnotation(); string startwith = node.FullPath.Substring(TDCGExplorer.SystemDB.arcs_path.Length+1); TDCGExplorer.TAHCompaction(startwith); } else { MessageBox.Show(TextResource.OnlyTAHDirectory, TextResource.Error, MessageBoxButtons.OK); } } catch (Exception exception) { TDCGExplorer.SetToolTips(TextResource.Error + ":" + exception.Message); Debug.WriteLine(exception.Message); } }
private void LookupMODRefToolStripMenuItem_Click(object sender, EventArgs e) { if (TDCGExplorer.BusyTest()) return; try { GenericZipTreeNode node = lastSelectTreeNode as GenericZipTreeNode; if (node != null) { AssignTagPageControl(new MODRefPage(node.Entry)); } else { MessageBox.Show(TextResource.ZipFileOnly, TextResource.Error, MessageBoxButtons.OK); } } catch (Exception exception) { TDCGExplorer.SetToolTips(TextResource.Error + ":" + exception.Message); Debug.WriteLine(exception.Message); } }
// TAHファイルを直接展開する. private void ExtractTahFileToolStripMenuItem_Click(object sender, EventArgs e) { if (TDCGExplorer.BusyTest()) return; try { int index = listBoxMainListBox.SelectedIndex; if (index >= 0) { LbGenItem item = listBoxMainListBox.Items[index] as LbGenItem; if (item != null) { item.DoDecrypt(); listBoxMainListBox.Focus(); } } } catch (Exception exception) { TDCGExplorer.SetToolTips(TextResource.Error + ":" + exception.Message); Debug.WriteLine(exception.Message); } }
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 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 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; } }
// arcsnames.zipを解凍、展開する. public void GetTagNamesZipInfo() { try { string localfile = zipTagLocalName(); string arcname = "tmp/tagnames.txt"; // ZIPファイルを展開する. IArchive arc = new ZipArchive(); arc.Open(localfile); if (arc == null) { return; } foreach (IArchiveEntry entry in arc) { if (entry.FileName == arcname) { TagNames.Clear(); using (MemoryStream ms = new MemoryStream((int)entry.Size)) { arc.Extract(entry, ms); ms.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(ms, System.Text.Encoding.GetEncoding("Shift_JIS")); Regex regCsv = new System.Text.RegularExpressions.Regex("\\s*(\"(?:[^\"]|\"\")*\"|[^,]*)\\s*,\\s*(\"(?:[^\"]|\"\")*\"|[^,]*)\\s*", RegexOptions.None); // CSVファイルを展開してarcsNamesを構築する. for (; ;) { string line = reader.ReadLine(); if (line == null) { break; } Match m = regCsv.Match(line); //TagNamesEntry tagentry = new TagNamesEntry(); string tag = null, code = null; while (m.Success) { for (int index = 1; index < 5; index++) { string field = m.Groups[index].Value; if (field == "\\N") { field = ""; } field = field.Trim(); if (field.StartsWith("\"") && field.EndsWith("\"")) { field = field.Substring(1, field.Length - 2); field = field.Replace("\"\"", "\""); } switch (index) { case 1: tag = field; break; case 2: code = field; break; } } m = m.NextMatch(); } if (TagNames.ContainsKey(tag) == false) { TagNamesEntry codeentry = new TagNamesEntry(); codeentry.tag = tag; TagNames[tag] = codeentry; } TagNames[tag].code.Add(code); } } } } } catch (Exception e) { TDCGExplorer.SetToolTips("Error GetTagNamesZipInfo : " + e.Message); } }
public void DoWorkerThread() { string moddb = TDCGExplorer.GetSystemDatabase().moddb_url; string relurl; ArcRels relationships; string msg = "<html><body>"; int count = 0; // Cursor.Current = Cursors.WaitCursor; try { relurl = moddb + "arcs/code/" + zipEntry.code + "/rels.xml"; TDCGExplorer.SetToolTips(relurl); relationships = ArcRels.Load(relurl); Arc thisarc = Arc.Load(moddb + "arcs/code/" + zipEntry.code + ".xml"); msg += "<h2><a href=" + moddb + "arcs/" + thisarc.Id + ">" + "MOD Archive code:" + zipEntry.code + "</a></h2>"; if (relationships != null) { if (relationships.Relationships != null) { foreach (Relationship relation in relationships.Relationships) { string arcurl = moddb + "arcs/" + relation.ToId.ToString() + ".xml"; string[] kindstr = { "0", "同一内容", "新版", "前提" }; try { Arc arc = Arc.Load(arcurl); if (arc != null) { msg += "<pre>"; msg += "属性:" + kindstr[relation.Kind] + "<br/>"; msg += "MODコード名:" + arc.Code + "<br/>"; msg += "サマリー:" + arc.Summary + "<br/>"; msg += "元ファイル名:" + arc.Origname + "<br/>"; msg += "拡張子:" + arc.Extname + "<br/>"; msg += "所在:" + arc.Location + "<br/>"; msg += "</pre>"; count++; } } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } } relurl = moddb + "arcs/code/" + zipEntry.code + "/revs.xml"; relationships = ArcRels.Load(relurl); if (relationships != null) { if (relationships.Relationships != null) { foreach (Relationship relation in relationships.Relationships) { if (relation.Kind == 1) { continue; } string arcurl = moddb + "arcs/" + relation.FromId.ToString() + ".xml"; string[] kindstr = { "0", "1", "旧版", "提供" }; try { Arc arc = Arc.Load(arcurl); if (arc != null) { msg += "<pre>"; msg += "属性:" + kindstr[relation.Kind] + "<br/>"; msg += "MODコード名:" + arc.Code + "<br/>"; msg += "サマリー:" + arc.Summary + "<br/>"; msg += "元ファイル名:" + arc.Origname + "<br/>"; msg += "拡張子:" + arc.Extname + "<br/>"; msg += "所在:" + arc.Location + "<br/>"; msg += "</pre>"; count++; } } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } // Cursor.Current = Cursors.Default; if (count == 0) { msg += "<p>関連情報がありません</p>"; } msg += "</body></html>"; page.asyncDisplayFromArcs(msg); }