private static void DecompileMapBackgroundWork(object sender, DoWorkEventArgs e) { var outputFile = (string)e.Argument; var filesToDecompile = (MapFiles)0; foreach (var checkBox in _filesToDecompileCheckBoxes) { if (checkBox.Checked) { filesToDecompile |= checkBox.MapFile; } } var decompiledMap = MapDecompiler.DecompileMap(_map, filesToDecompile, _worker); if (decompiledMap is null) { return; } var mapBuilder = new MapBuilder(decompiledMap); mapBuilder.AddFiles(_archive); mapBuilder.Build(outputFile); }
private void Decompile() { //Initialize OpenFileDialog openDlg = new OpenFileDialog() { Filter = "Halo Map Files (*.map)|*.map" }; //Show if (openDlg.ShowDialog() ?? false) { //Prepare decompiling = true; string tagsDirectory = Path.Combine(RegistrySettings.WorkspaceDirectory, "tags"); decompiler = new MapDecompiler(openDlg.FileName, tagsDirectory) { Host = this }; Status = $"Decompiling {decompiler.map.Name}..."; ShowProgressBar = true; Progress = 0d; //Start decompiler.Start(); } }
void IDecompileReporter.Fail() { //Set status Status = $"{decompiler.map.Name} failed to decompile"; ShowProgressBar = false; Progress = 0d; //Dispose decompiling = false; decompiler.Dispose(); decompiler = null; }
void IDecompileReporter.Complete() { //Set status Status = $"{decompiler.map.Name} Decompiled successfully"; ShowProgressBar = false; Progress = 0d; //Dispose decompiling = false; decompiler.Dispose(); decompiler = null; }
private static void Main(string[] args) { _watcher = new FileSystemWatcher(); _watcher.Created += OnWatchedFileEvent; _watcher.Renamed += OnWatchedFileEvent; _watcher.Deleted += OnWatchedFileEvent; var form = new Form(); form.Text = Title; _archiveInput = new TextBox { PlaceholderText = "Input map...", }; _openCloseArchiveButton = new Button { Text = "Open archive", Enabled = false, }; _saveAsButton = new Button { Text = "Save As...", }; _saveAsButton.Size = _saveAsButton.PreferredSize; _saveAsButton.Enabled = false; _autoDetectFilesToDecompileButton = new Button { Text = "Detect files to decompile", }; _autoDetectFilesToDecompileButton.Size = _autoDetectFilesToDecompileButton.PreferredSize; _autoDetectFilesToDecompileButton.Enabled = false; _filesToDecompileCheckBoxes = new[] { new MapFileCheckBox(MapFiles.Sounds, MapSounds.FileName), new MapFileCheckBox(MapFiles.Cameras, MapCameras.FileName), new MapFileCheckBox(MapFiles.Regions, MapRegions.FileName), new MapFileCheckBox(MapFiles.Triggers, MapSounds.FileName), new MapFileCheckBox(MapFiles.Units, MapUnits.FileName), }; foreach (var checkBox in _filesToDecompileCheckBoxes) { checkBox.Size = checkBox.PreferredSize; checkBox.Enabled = false; checkBox.CheckedChanged += (s, e) => { _saveAsButton.Enabled = _filesToDecompileCheckBoxes.Any(checkBox => checkBox.Checked); }; } _archiveInput.TextChanged += OnArchiveInputTextChanged; _archiveInputBrowseButton = new Button { Text = "Browse", }; _archiveInputBrowseButton.Size = _archiveInputBrowseButton.PreferredSize; _archiveInputBrowseButton.Click += (s, e) => { var openFileDialog = new OpenFileDialog { CheckFileExists = false, }; openFileDialog.Filter = string.Join('|', new[] { "Warcraft III map|*.w3m;*.w3x", "All files|*.*", }); var openFileDialogResult = openFileDialog.ShowDialog(); if (openFileDialogResult == DialogResult.OK) { _archiveInput.Text = openFileDialog.FileName; } }; _openCloseArchiveButton.Size = _openCloseArchiveButton.PreferredSize; _openCloseArchiveButton.Click += OnClickOpenCloseMap; _saveAsButton.Click += (s, e) => { var saveFileDialog = new SaveFileDialog { OverwritePrompt = true, CreatePrompt = false, }; var saveFileDialogResult = saveFileDialog.ShowDialog(); if (saveFileDialogResult == DialogResult.OK) { _progressBar.CustomText = "Starting..."; _progressBar.Value = 0; _openCloseArchiveButton.Enabled = false; _saveAsButton.Enabled = false; _autoDetectFilesToDecompileButton.Enabled = false; foreach (var checkBox in _filesToDecompileCheckBoxes) { checkBox.Enabled = false; } _progressBar.Visible = true; _worker.RunWorkerAsync(saveFileDialog.FileName); } }; _autoDetectFilesToDecompileButton.Click += (s, e) => { var filesToDecompile = MapDecompiler.AutoDetectMapFilesToDecompile(_map); foreach (var checkBox in _filesToDecompileCheckBoxes) { checkBox.Checked = filesToDecompile.HasFlag(checkBox.MapFile); } }; _progressBar = new TextProgressBar { Dock = DockStyle.Bottom, Style = ProgressBarStyle.Continuous, VisualMode = TextProgressBar.ProgressBarDisplayMode.CustomText, Visible = false, }; _worker = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true, }; _worker.DoWork += DecompileMapBackgroundWork; _worker.ProgressChanged += DecompileMapProgressChanged; _worker.RunWorkerCompleted += DecompileMapCompleted; // Initialize parser JassSyntaxFactory.ParseCompilationUnit(string.Empty); var flowLayout = new FlowLayoutPanel { Dock = DockStyle.Fill, FlowDirection = FlowDirection.TopDown, WrapContents = false, }; var inputArchiveFlowLayout = new FlowLayoutPanel { FlowDirection = FlowDirection.LeftToRight, }; var buttonsFlowLayout = new FlowLayoutPanel { FlowDirection = FlowDirection.LeftToRight, }; var checkBoxesFlowLayout = new FlowLayoutPanel { FlowDirection = FlowDirection.TopDown, WrapContents = false, }; inputArchiveFlowLayout.AddControls(_archiveInput, _archiveInputBrowseButton, _openCloseArchiveButton); buttonsFlowLayout.AddControls(_saveAsButton, _autoDetectFilesToDecompileButton); checkBoxesFlowLayout.AddControls(_filesToDecompileCheckBoxes); checkBoxesFlowLayout.Size = checkBoxesFlowLayout.PreferredSize; flowLayout.AddControls(inputArchiveFlowLayout, buttonsFlowLayout, checkBoxesFlowLayout); form.AddControls(flowLayout, _progressBar); form.SizeChanged += (s, e) => { var width = form.Width; _archiveInput.Width = (width > 360 ? 360 : width) - 10; inputArchiveFlowLayout.Size = inputArchiveFlowLayout.GetPreferredSize(new Size(width, 0)); buttonsFlowLayout.Size = buttonsFlowLayout.GetPreferredSize(new Size(width, 0)); flowLayout.Height = inputArchiveFlowLayout.Margin.Top + inputArchiveFlowLayout.Height + inputArchiveFlowLayout.Margin.Bottom + buttonsFlowLayout.Margin.Top + buttonsFlowLayout.Height + buttonsFlowLayout.Margin.Bottom; }; form.Size = new Size(400, 400); form.MinimumSize = new Size(400, 300); form.FormClosing += (s, e) => { _archive?.Dispose(); _worker?.Dispose(); }; form.ShowDialog(); }