Example #1
0
        public mainForm()
        {
            InitializeComponent();

            //add control events
            Load += (s, e) =>
            {
                keys = new UI.Keys();
                if (File.Exists("keys.json"))
                {
                    keys.Load("keys.json");
                }
            };

            Shown += (s, e) => { LoadKeys(); };

            FormClosing += (s, e) =>
            {
                if (!Equals(null, contentMeta))
                {
                    contentMeta.Dispose();
                }
                keys.Save("keys.json");
            };

            keysButton.Click += (s, e) =>
            {
                keys = new keyForm().ShowDialog(this, keys);
                LoadKeys();
            };

            openButton.Click += (s, e) =>
            {
                using (OpenFileDialog open = new OpenFileDialog())
                {
                    open.Filter = "Xbox Content (*.xbx)|*.xbx|All Files (*.*)|*.*";
                    if (open.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    Open(open.FileName);
                }
            };

            batchButton.Click += (s, e) =>
            {
                keys = new batchForm().ShowDialog(this, keys);
                LoadKeys();
            };

            createPathButton.Click += (s, e) =>
            {
                if (Equals(null, contentMeta))
                {
                    return;
                }
                using (FolderBrowserDialog folder = new FolderBrowserDialog())
                {
                    folder.Description = "Select where content path will be created";
                    if (folder.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    DirectoryInfo directory = Directory.CreateDirectory(string.Format("{0}{1}", folder.SelectedPath, contentMeta.RelativePath));
                    MessageBox.Show(string.Format("Content path created:\n\n{0}", directory.FullName));
                }
            };

            signButton.Click += (s, e) =>
            {
                if (Equals(null, contentMeta))
                {
                    return;
                }
                if (keys.Count == 0)
                {
                    MessageBox.Show("You must add a key to sign content with");
                    return;
                }
                string alias = (string)keyBox.SelectedItem;
                if (string.IsNullOrEmpty(alias))
                {
                    MessageBox.Show("Invalid key selected");
                    return;
                }
                bool   exists;
                byte[] key = keys.GetKey(alias, out exists);
                if (!exists)
                {
                    MessageBox.Show("Selected key does not exist");
                    return;
                }
                bool skipContentHashing = skipBox.Checked;
                Sign(key, skipContentHashing);
            };
        }
Example #2
0
        public batchForm()
        {
            batchItems = new List <ContentMeta>();
            InitializeComponent();
            if (!toolbar.Contains(skipBox))
            {
                Win32.SuspendDrawing(this);
                toolbar.Items.Insert(3, new ToolStripControlHost(skipBox));
                Win32.ResumeDrawing(this);
            }

            Shown += (s, e) => { LoadKeys(); };

            FormClosing += (s, e) =>
            {
                if (!Equals(null, batchItems) && batchItems.Count > 0)
                {
                    foreach (ContentMeta contentMeta in batchItems)
                    {
                        contentMeta.Dispose();
                    }
                    batchItems.Clear();
                }
            };

            keysButton.Click += (s, e) =>
            {
                keys = new keyForm().ShowDialog(this, keys);
                LoadKeys();
            };

            clearButton.Click += (s, e) =>
            {
                if (Equals(null, batchItems))
                {
                    return;
                }
                foreach (ContentMeta contentMeta in batchItems)
                {
                    contentMeta.Dispose();
                }
                batchItems.Clear();
                LoadItems();
            };

            addButton.Click += (s, e) =>
            {
                string path;
                using (FolderBrowserDialog folder = new FolderBrowserDialog())
                {
                    folder.Description = "Select folder containing ContentMeta.xbx files";
                    if (folder.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    path = folder.SelectedPath;
                }

                IEnumerable <string> files = Directory.EnumerateFiles(path, "*.xbx", SearchOption.AllDirectories);
                if (Equals(null, files) || files.Count() == 0)
                {
                    MessageBox.Show("No .xbx files found");
                    return;
                }

                List <ContentMeta> items = new List <ContentMeta>();
                ContentMeta        item;
                bool success;
                foreach (string file in files)
                {
                    item = new ContentMeta(file, out success);
                    foreach (ContentMeta contentMeta in batchItems)
                    {
                        if (contentMeta.FilePath == file)
                        {
                            success = false;
                            break;
                        }
                    }
                    if (success)
                    {
                        items.Add(item);
                    }
                }

                if (items.Count == 0)
                {
                    MessageBox.Show("No valid .xbx files found");
                    return;
                }

                batchItems.AddRange(items);
                LoadItems();
            };

            signButton.Click += (s, e) =>
            {
                if (Equals(null, batchItems) || batchItems.Count == 0)
                {
                    return;
                }
                if (keys.Count == 0)
                {
                    MessageBox.Show("You must add a key to sign content with");
                    return;
                }
                string alias = (string)keyBox.SelectedItem;
                if (string.IsNullOrEmpty(alias))
                {
                    MessageBox.Show("Invalid key selected");
                    return;
                }
                bool   exists;
                byte[] key = keys.GetKey(alias, out exists);
                if (!exists)
                {
                    MessageBox.Show("Selected key does not exist");
                    return;
                }
                bool   skipContentHashing = skipBox.Checked;
                string result;
                new Thread(delegate()
                {
                    Invoke((Action) delegate
                    {
                        signButton.Enabled  = false;
                        addButton.Enabled   = false;
                        clearButton.Enabled = false;
                        keysButton.Enabled  = false;

                        foreach (ListViewItem item in fileList.Items)
                        {
                            item.SubItems[1].Text = null;
                        }
                        fileList.RedrawItems(0, (fileList.Items.Count - 1), false);
                    });

                    int i = 0;
                    foreach (ContentMeta contentMeta in batchItems)
                    {
                        result = Sign(contentMeta, key, skipContentHashing);
                        Invoke((Action) delegate
                        {
                            fileList.Items[i].SubItems[1].Text = result;
                            fileList.RedrawItems(i, i, false);
                        });
                        i++;
                    }

                    Invoke((Action) delegate
                    {
                        signButton.Enabled  = true;
                        addButton.Enabled   = true;
                        clearButton.Enabled = true;
                        keysButton.Enabled  = true;
                    });

                    Thread.CurrentThread.Abort();
                }).Start();
            };
        }