コード例 #1
0
        private void tmrCheckThread_Tick(object sender, EventArgs e)
        {
            if (tpupThread != null)
            {
                if (tpupThread.IsAlive)
                {
                    updateLogs();
                }
                else
                {
                    // Make sure to clear out any leftover messages
                    updateLogs();

                    tpup                = null;
                    tpupThread          = null;
                    pbrProgress.Maximum = 0;
                    pbrProgress.Value   = 0;
                    lblProgress.Text    = "Progress";
                    enableControls(true);

                    if (abort)
                    {
                        Close();
                    }
                    else
                    {
                        SystemSounds.Asterisk.Play();
                    }
                }
            }
        }
コード例 #2
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            string filepath = txtConvertFile.Text;

            if (File.Exists(filepath))
            {
                if (File.Exists("bin\\texconv.exe"))
                {
                    ConvertFormatItem formatItem = cmbConvertFormat.SelectedItem as ConvertFormatItem;
                    if (formatItem == null)
                    {
                        return;
                    }
                    DXGIFormat format = formatItem.Format;

                    filepath = Path.GetFullPath(filepath);
                    string directory = Path.GetDirectoryName(filepath);

                    bool backedUp = false;
                    if (Path.GetExtension(filepath) == ".dds" && !File.Exists(filepath + ".bak"))
                    {
                        backedUp = true;
                        File.Copy(filepath, filepath + ".bak");
                    }

                    string args = string.Format("-f {0} -o \"{1}\" \"{2}\" -y",
                                                TPUP.PrintDXGIFormat(format), directory, filepath);
                    ProcessStartInfo startInfo = new ProcessStartInfo("bin\\texconv.exe", args)
                    {
                        CreateNoWindow         = true,
                        UseShellExecute        = false,
                        RedirectStandardOutput = true
                    };
                    Process texconv = Process.Start(startInfo);
                    texconv.WaitForExit();

                    if (texconv.ExitCode == 0)
                    {
                        appendLog("Conversion successful!");
                        SystemSounds.Asterisk.Play();
                    }
                    else
                    {
                        MessageBox.Show("Conversion failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        if (backedUp)
                        {
                            File.Move(filepath + ".bak", filepath);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("texconv.exe not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("File to be converted does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
        private void btnRepack_Click(object sender, EventArgs e)
        {
            string gameDir   = txtGameDir.Text;
            string repackDir = txtRepackDir.Text;

            if (!Directory.Exists(gameDir))
            {
                MessageBox.Show("Game directory not found:\n" + gameDir,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (!Directory.Exists(repackDir))
            {
                MessageBox.Show("Override directory not found:\n" + repackDir,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                bool proceed = true;
                try
                {
                    File.WriteAllText(repackDir + "\\tpup_test.txt",
                                      "Test file to see if TPUP can write to this directory.");
                    File.Delete(repackDir + "\\tpup_test.txt");
                }
                catch (Exception ex) when(ex is IOException || ex is UnauthorizedAccessException)
                {
                    MessageBox.Show("Repack 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();
                    txtError.Clear();
                    pbrProgress.Value   = 0;
                    pbrProgress.Maximum = 0;
                    tpup       = new TPUP(gameDir, repackDir, true, cbxPreserveConverted.Checked, (int)nudThreads.Value);
                    tpupThread = new Thread(tpup.Start);
                    tpupThread.Start();
                }
            }
        }
コード例 #4
0
 public override string ToString()
 {
     return(TPUP.PrintDXGIFormat(Format));
 }
コード例 #5
0
        private async void FormMain_Load(object sender, EventArgs e)
        {
            Text     = "DSR Texture Packer & Unpacker " + System.Windows.Forms.Application.ProductVersion;
            Location = settings.WindowLocation;
            Size     = settings.WindowSize;
            if (settings.WindowMaximized)
            {
                WindowState = FormWindowState.Maximized;
            }

            txtGameDir.Text              = settings.GameDir;
            txtUnpackDir.Text            = settings.UnpackDir;
            txtRepackDir.Text            = settings.RepackDir;
            cbxPreserveConverted.Checked = settings.PreserveConverted;
            txtConvertFile.Text          = settings.ConvertFile;
            tclMain.SelectedIndex        = settings.TabSelected;
            spcLogs.SplitterDistance     = settings.SplitterDistance;

            nudThreads.Maximum = Environment.ProcessorCount;
            if (settings.Threads == 0 || settings.Threads > Environment.ProcessorCount)
            {
                settings.Threads = Environment.ProcessorCount;
            }
            nudThreads.Value = settings.Threads;

            enableControls(true);

            // Force common formats to the top
            List <DXGIFormat> outOfOrder = new List <DXGIFormat> {
                DXGIFormat.BC1_UNorm,
                DXGIFormat.BC2_UNorm,
                DXGIFormat.BC3_UNorm,
                DXGIFormat.BC5_UNorm,
                DXGIFormat.BC7_UNorm,
            };

            foreach (DXGIFormat format in outOfOrder)
            {
                cmbConvertFormat.Items.Add(new ConvertFormatItem(format));
            }

            cmbConvertFormat.Items.Add("--------------------------------------------------");

            List <DXGIFormat> inOrder = new List <DXGIFormat>();

            foreach (DXGIFormat format in Enum.GetValues(typeof(DXGIFormat)))
            {
                if (!outOfOrder.Contains(format) && format != DXGIFormat.Unknown)
                {
                    inOrder.Add(format);
                }
            }

            inOrder.Sort((f1, f2) => TPUP.PrintDXGIFormat(f1).CompareTo(TPUP.PrintDXGIFormat(f2)));
            foreach (DXGIFormat format in inOrder)
            {
                cmbConvertFormat.Items.Add(new ConvertFormatItem(format));
            }
            cmbConvertFormat.SelectedIndex = 0;

            GitHubClient gitHubClient = new GitHubClient(new ProductHeaderValue("DSR-TPUP"));

            try
            {
                Release release = await gitHubClient.Repository.Release.GetLatest("JKAnderson", "DSR-TPUP");

                if (SemVersion.Parse(release.TagName) > System.Windows.Forms.Application.ProductVersion)
                {
                    lblUpdate.Visible = false;
                    LinkLabel.Link link = new LinkLabel.Link();
                    link.LinkData = UPDATE_LINK;
                    llbUpdate.Links.Add(link);
                    llbUpdate.Visible = true;
                }
                else
                {
                    lblUpdate.Text = "App up to date";
                }
            }
            catch (Exception ex) when(ex is HttpRequestException || ex is ApiException || ex is ArgumentException)
            {
                lblUpdate.Text = "Update status unknown";
            }
        }
コード例 #6
0
        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();
                        txtError.Clear();
                        pbrProgress.Value   = 0;
                        pbrProgress.Maximum = 0;
                        tpup       = new TPUP(txtGameDir.Text, unpackDir, false, false, (int)nudThreads.Value);
                        tpupThread = new Thread(tpup.Start);
                        tpupThread.Start();
                    }
                }
            }
        }