static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); HspConsole.Initialize(); if (!HspDecoder.Initialize()) { HspConsole.Close(); return; } string filename = null; if ((args != null) && (args.Length > 0)) { foreach (string file in args) { if (File.Exists(file)) { filename = file; break; } } } try { Application.Run(new deHspDialog(filename)); } catch (Exception e) { try { HspConsole.ExceptionHandlingClose(e); } catch { } return; } HspConsole.Close(); }
private void Do(string filePath) { txtBoxMainInfo.Text = ""; global::KttK.HspDecompiler.HspConsole.DecompStart(filePath); HspDecoder decoder = new HspDecoder(); string dirName = Path.GetDirectoryName(filePath) + Path.DirectorySeparatorChar; string inputFileName = Path.GetFileNameWithoutExtension(filePath); int i = 1; string errorPath = filePath + ".log"; FileStream stream = null; BinaryReader reader = null; StreamWriter errorlog = null; try { global::KttK.HspDecompiler.HspConsole.Write(Path.GetFileName(filePath) + "を読み込み"); stream = new FileStream(filePath, FileMode.Open, FileAccess.Read); reader = new BinaryReader(stream, Encoding.GetEncoding("SHIFT-JIS")); char[] buffer = reader.ReadChars(4); string bufStr = new string(buffer); reader.BaseStream.Seek(0, SeekOrigin.Begin); if (bufStr.StartsWith("MZ", StringComparison.Ordinal) || bufStr.StartsWith("DPM", StringComparison.Ordinal)) { dirName = Path.GetDirectoryName(filePath) + Path.DirectorySeparatorChar + inputFileName; i = 1; while (Directory.Exists(dirName)) { dirName = string.Format(@"{0}\{1} ({2})", Path.GetDirectoryName(filePath), inputFileName, i); i++; } errorPath = dirName + ".log"; dirName = dirName + Path.DirectorySeparatorChar; decoder.DecompressDpm(reader, this.dpmFileList, dirName); } else if (bufStr.StartsWith("HSP2", StringComparison.Ordinal) || bufStr.StartsWith("HSP3", StringComparison.Ordinal)) { string outputFileExtention = null; if (bufStr.StartsWith("HSP2", StringComparison.Ordinal)) { outputFileExtention = ".as"; } else { outputFileExtention = ".hsp"; } string outputFileName = inputFileName; string outputPath = dirName + outputFileName + outputFileExtention; while (File.Exists(outputPath)) { outputFileName = string.Format("{0} ({1})", inputFileName, i); outputPath = dirName + outputFileName + outputFileExtention; i++; } decoder.Decode(reader, outputPath); errorPath = outputPath + ".log"; } else { throw new HspDecoderException("処理できないファイル形式です"); } int warCount = global::KttK.HspDecompiler.HspConsole.Warnings.Count; if (warCount != 0) { MessageBox.Show(Path.GetFileName(errorPath) + "にエラーを出力します", "コードを完全には復元できませんでした"); errorlog = new StreamWriter(errorPath, false, Encoding.GetEncoding("SHIFT-JIS")); foreach (string line in global::KttK.HspDecompiler.HspConsole.Warnings) { errorlog.WriteLine(line); } } } catch (Exception e) { global::KttK.HspDecompiler.HspConsole.FatalError(e); return; } finally { if (reader != null) { reader.Close(); } else if (stream != null) { stream.Close(); } if (errorlog != null) { errorlog.Close(); } } }