private void tmrUpdate_Tick(object sender, EventArgs e) { if (tpupThread != null) { if (tpupThread.IsAlive) { updateLogs(); } else { updateLogs(); tpup = null; tpupThread = null; pbrProgress.Maximum = 0; pbrProgress.Value = 0; enableControls(true); if (abort) { Close(); } else { SystemSounds.Asterisk.Play(); } } } }
private void btnRandomize_Click(object sender, EventArgs e) { string gameDir = txtGameDir.Text; string unpackDir = txtUnpackDir.Text; if (!Directory.Exists(gameDir)) { MessageBox.Show("Game directory not found:\n" + gameDir, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!Directory.Exists(unpackDir)) { MessageBox.Show("Unpacked directory not found:\n" + unpackDir, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { bool proceed = true; unpackDir = Path.GetFullPath(unpackDir); try { File.WriteAllText(unpackDir + "\\tpup_test.txt", "Test file to see if TPUP can write to this directory."); File.Delete(unpackDir + "\\tpup_test.txt"); } catch (Exception ex) when(ex is IOException || ex is UnauthorizedAccessException) { MessageBox.Show("Unpack directory could not be written to. Try running as Administrator.\n" + "Reason: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); proceed = false; } if (proceed) { Dictionary <string, string> swaps = null; if (!(cbxChrIn.Checked || cbxMapIn.Checked || cbxObjIn.Checked || cbxPartsIn.Checked || cbxSfxIn.Checked || cbxCustomIn.Checked)) { MessageBox.Show("You must check at least one input.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!(cbxChrOut.Checked || cbxMapOut.Checked || cbxObjOut.Checked || cbxPartsOut.Checked || cbxSfxOut.Checked)) { MessageBox.Show("You must check at least one output.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { swaps = getTextureSwaps(unpackDir, txtCustomDir.Text); } if (swaps != null) { enableControls(false); txtLog.Clear(); pbrProgress.Value = 0; pbrProgress.Maximum = 0; tpup = new TPUP(gameDir, unpackDir, true, swaps, (int)nudThreads.Value); tpupThread = new Thread(tpup.Start); tpupThread.Start(); } } } }
private void btnUnpack_Click(object sender, EventArgs e) { string unpackDir; try { unpackDir = Path.GetFullPath(txtUnpackDir.Text); } catch (ArgumentException) { MessageBox.Show("Invalid output path:\n" + txtUnpackDir.Text, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!Directory.Exists(txtGameDir.Text)) { MessageBox.Show("Game directory not found:\n" + txtGameDir.Text, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DialogResult result = DialogResult.OK; if (Directory.Exists(txtUnpackDir.Text)) { result = MessageBox.Show("The contents of this directory will be deleted:\n" + unpackDir, "Warning!", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); } if (result == DialogResult.OK) { bool proceed = true; try { if (Directory.Exists(unpackDir)) { appendLog("Deleting unpack directory..."); Directory.Delete(unpackDir, true); } } catch (Exception ex) when(ex is IOException || ex is UnauthorizedAccessException) { MessageBox.Show("Unpack directory could not be deleted. Try running as Administrator.\n" + "Reason: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); proceed = false; } try { if (proceed) { Directory.CreateDirectory(unpackDir); File.WriteAllText(unpackDir + "\\tpup_test.txt", "Test file to see if TPUP can write to this directory."); File.Delete(unpackDir + "\\tpup_test.txt"); } } catch (Exception ex) when(ex is IOException || ex is UnauthorizedAccessException) { MessageBox.Show("Unpack directory could not be written to. Try running as Administrator.\n" + "Reason: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); proceed = false; } if (proceed) { enableControls(false); txtLog.Clear(); pbrProgress.Value = 0; pbrProgress.Maximum = 0; tpup = new TPUP(txtGameDir.Text, unpackDir, false, null, (int)nudThreads.Value); tpupThread = new Thread(tpup.Start); tpupThread.Start(); } } } }