Ejemplo n.º 1
0
        private void _ReanimatorLoad(object sender, EventArgs e)
        {
            try
            {
                Height = Config.ClientHeight;
                Width  = Config.ClientWidth;
                Show();
                Refresh();

                if (_CheckInstallation())
                {
                    ProgressForm progressForm = new ProgressForm(_DoLoadingThread, null);
                    progressForm.SetStyle(ProgressBarStyle.Marquee);
                    progressForm.SetLoadingText("Initializing Reanimator subsystems...");
                    progressForm.Disposed += delegate
                    {
                        _OpenExcelTableEditor();
                        _OpenExcelTableEditorTCv4();

                        if (Config.ShowFileExplorer)
                        {
                            _OpenFileExplorer();
                        }
                    };
                    progressForm.Show(this);
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                MessageBox.Show(ex.Message, "ReanimatorLoad");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new data table inside a tabbed control.
        /// </summary>
        /// <param name="id">string id associated with the datafile</param>
        public void CreateTab(String id)
        {
            DataFile       dataFile = _fileManager.GetDataFile(id);
            DatafileEditor editor   = new DatafileEditor(dataFile, _fileManager)
            {
                Dock = DockStyle.Fill
            };
            TabPage tabPage = new TabPage(id)
            {
                Parent = _tabControl, Name = id
            };

            // must disconnect the DataGridView forms controls from the DataSet to modify it (the DataSet) in a non-UI thread; see: (essentially the problem we were having)
            // http://connect.microsoft.com/VisualStudio/feedback/details/117148/datagridview-throws-system-invalidoperationexception-when-used-with-a-ibindinglist-that-raises-listchanged-on-a-background-thread
            // while we are disconnecting every grid view, we only actually need to do it if it's going to be modified due to relations
            // however this doesn't appear to lag them or the process in any significant manner, so this will do
            foreach (DatafileEditor datafileEditor in _datafileEditors)
            {
                datafileEditor.DisconnectFromDataSet();
            }

            ProgressForm progress = new ProgressForm(editor.InitThreadedComponents, null);

            progress.SetStyle(ProgressBarStyle.Marquee);
            progress.SetLoadingText("Generating DataTable...");
            progress.SetCurrentItemText(String.Empty);
            progress.ShowDialog(this);

            _tabControl.SuspendLayout();
            tabPage.SuspendLayout();
            tabPage.Controls.Add(editor);
            editor.AddedToTabPage = true;
            tabPage.ResumeLayout();
            _tabControl.ResumeLayout();

            foreach (DatafileEditor datafileEditor in _datafileEditors)
            {
                datafileEditor.ReconnectToDataSet();
            }

            _datafileEditors.Add(editor);
        }
Ejemplo n.º 3
0
        private void _OpenFileExplorer()
        {
            if (_fileExplorer != null && !_fileExplorer.IsDisposed) // it works - but probably should be tested a bit more if we keep this option
            {
                DialogResult dr = MessageBox.Show("An instance of FileExplorer is already open.\nDo you want to open another instance? (Not fully tested)", "Already Open",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.No)
                {
                    return;
                }
            }

            ProgressForm progressForm = new ProgressForm(_LoadFileExplorerThread, null);

            progressForm.SetStyle(ProgressBarStyle.Marquee);
            progressForm.SetLoadingText("Initializing File Explorer...");
            progressForm.SetCurrentItemText("");
            progressForm.Disposed += delegate { _fileExplorer.Show(); };
            progressForm.Show(this);
        }
Ejemplo n.º 4
0
        private void _ReanimatorLoad(object sender, EventArgs e)
        {
            try
            {
                Height = Config.ClientHeight;
                Width = Config.ClientWidth;
                Show();
                Refresh();

                if (_CheckInstallation())
                {
                    ProgressForm progressForm = new ProgressForm(_DoLoadingThread, null);
                    progressForm.SetStyle(ProgressBarStyle.Marquee);
                    progressForm.SetLoadingText("Initializing Reanimator subsystems...");
                    progressForm.Disposed += delegate
                    {
                        _OpenExcelTableEditor();
                        _OpenExcelTableEditorTCv4();

                        if (Config.ShowFileExplorer) _OpenFileExplorer();
                    };
                    progressForm.Show(this);
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                MessageBox.Show(ex.Message, "ReanimatorLoad");
            }
        }
Ejemplo n.º 5
0
        private void _DoPackPatch(ProgressForm progressForm, Object param)
        {
            ExtractPackPatchArgs args = (ExtractPackPatchArgs)param;

            // find which checked nodes actually have files we can pack
            StringWriter packResults = new StringWriter();

            String state = String.Format("Checking {0} file(s) for packing...", args.CheckedNodes.Count);
            const int packCheckStep = 200;
            progressForm.SetLoadingText(state);
            progressForm.ConfigBar(0, args.CheckedNodes.Count, packCheckStep);
            packResults.WriteLine(state);

            int i = 0;
            List<TreeNode> packNodes = new List<TreeNode>();
            foreach (TreeNode checkedNode in args.CheckedNodes)
            {
                String filePath = Path.Combine(args.RootDir, checkedNode.FullPath);

                if (i % packCheckStep == 0)
                {
                    progressForm.SetCurrentItemText(filePath);
                }
                i++;

                // ensure exists
                if (!File.Exists(filePath))
                {
                    packResults.WriteLine("{0} - File Not Found", filePath);
                    continue;
                }

                // ensure it was once packed (need FilePathHash etc)
                // todo: implement Crypt.StringHash for FilePathHash and FolderPathHash
                NodeObject nodeObject = (NodeObject)checkedNode.Tag;
                if (nodeObject.FileEntry == null ||
                    nodeObject.FileEntry.NameHash == 0)
                {
                    packResults.WriteLine("{0} - File Has No Base Version", filePath);
                    continue;
                }

                packResults.WriteLine(filePath);
                packNodes.Add(checkedNode);
            }

            // write our error log if we have it
            const String packResultsFile = "packResults.log";
            if (packNodes.Count != args.CheckedNodes.Count)
            {
                try
                {
                    File.WriteAllText(packResultsFile, packResults.ToString());
                }
                catch (Exception e)
                {
                    MessageBox.Show("Failed to write to log file!\n\n" + e, "Warning", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                }

                // can we pack any?
                if (packNodes.Count == 0)
                {
                    String errorMsg =
                        String.Format("None of the {0} files were able to be packed!\nSee {1} for more details.",
                                      args.CheckedNodes.Count, packResultsFile);
                    MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                    return;
                }
                else
                {
                    String errorMsg =
                        String.Format("Of the {0} files checked, only {1} will be able to be packed.\nSee {2} for more details.\n\nContinue with packing and patching process?",
                                      args.CheckedNodes.Count, packNodes.Count, packResultsFile);
                    DialogResult continuePacking = MessageBox.Show(errorMsg, "Notice", MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Information);
                    if (continuePacking == DialogResult.No) return;
                }
            }

            // pack our files
            // todo: rewrite
            //if (!_BeginDatAccess(IndexFiles, true))
            //{
            //    MessageBox.Show(
            //        "Failed to open dat files for writing!\nEnsure no other programs are using them and try again.",
            //        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    return;
            //}

            state = String.Format("Packing {0} files...", packNodes.Count);
            progressForm.ConfigBar(0, packNodes.Count, packCheckStep);
            progressForm.SetLoadingText(state);
            packResults.WriteLine(state);

            i = 0;
            bool allNodesPacked = true;
            bool datNeedsCleaning = false;
            foreach (TreeNode packNode in packNodes)
            {
                NodeObject oldNodeObject = (NodeObject)packNode.Tag;

                if (i % packCheckStep == 0)
                {
                    progressForm.SetCurrentItemText(packNode.FullPath);
                }
                i++;

                // add to our custom index if not already present
                PackFileEntry fileEntry = null; // todo: rewrite args.PackIndex.GetFileFromIndex(packNode.FullPath);
                if (fileEntry == null)
                {
                    //fileEntry = args.PackIndex.AddFileToIndex(oldNodeObject.FileEntry);
                }
                else
                {
                    // file exists - we'll need to clean the dat afterwards and remove orphaned data bytes
                    datNeedsCleaning = true;
                }

                // update fileTime to now - ensures it will override older versions
                fileEntry.FileTime = DateTime.Now.ToFileTime();

                // read in file data
                String filePath = Path.Combine(Config.HglDir, packNode.FullPath);
                byte[] fileData;
                try
                {
                    fileData = File.ReadAllBytes(filePath);
                }
                catch (Exception)
                {
                    packResults.WriteLine("{0} - Failed to read file data", filePath);
                    allNodesPacked = false;
                    continue;
                }

                // append to dat file
                try
                {
                    // todo: rewite args.PackIndex.AddFileToDat(fileData, fileEntry);
                }
                catch (Exception)
                {
                    packResults.WriteLine("{0} - Failed to add to data file", filePath);
                    allNodesPacked = false;
                    continue;
                }

                packResults.WriteLine(filePath);

                // update our node object while we're here
                //oldNodeObject.AddSibling(oldNodeObject);
                //NodeObject newNodeObject = new NodeObject
                //{
                //    Siblings = oldNodeObject.Siblings,
                //    CanEdit = oldNodeObject.CanEdit,
                //    FileEntry = fileEntry,
                //    Index = args.PackIndex,
                //    IsFolder = false
                //};

                //packNode.Tag = newNodeObject;
                //packNode.ForeColor = BaseColor;
            }

            // were all files packed?
            if (!allNodesPacked)
            {
                try
                {
                    File.WriteAllText(packResultsFile, packResults.ToString());
                }
                catch (Exception e)
                {
                    MessageBox.Show("Failed to write to log file!\n\n" + e, "Warning", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                }

                String warningMsg = String.Format("Not all files were packed!\nCheck {0} for more details.",
                                                packResultsFile);
                MessageBox.Show(warningMsg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            // do we need to clean our dat?
            progressForm.SetLoadingText("Generating and saving files...");
            progressForm.SetStyle(ProgressBarStyle.Marquee);
            if (datNeedsCleaning)
            {
                progressForm.SetCurrentItemText("Removing orphan data...");
                // todo: rewrite args.PackIndex.RebuildDatFile();
            }
            _fileManager.EndAllDatAccess();

            // write updated index
            progressForm.SetCurrentItemText("Writing update dat index...");
            try
            {
                byte[] idxBytes = args.PackIndex.ToByteArray();
                Crypt.Encrypt(idxBytes);
                File.WriteAllBytes(args.PackIndex.FilePath, idxBytes);
            }
            catch (Exception e)
            {
                MessageBox.Show("Failed to write updated index file!\n\n" + e, "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            MessageBox.Show("File packing and idx/dat writing completed!", "Success", MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
        }
Ejemplo n.º 6
0
        private void _OpenFileExplorer()
        {
            if (_fileExplorer != null && !_fileExplorer.IsDisposed) // it works - but probably should be tested a bit more if we keep this option
            {
                DialogResult dr = MessageBox.Show("An instance of FileExplorer is already open.\nDo you want to open another instance? (Not fully tested)", "Already Open",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.No) return;
            }

            ProgressForm progressForm = new ProgressForm(_LoadFileExplorerThread, null);
            progressForm.SetStyle(ProgressBarStyle.Marquee);
            progressForm.SetLoadingText("Initializing File Explorer...");
            progressForm.SetCurrentItemText("");
            progressForm.Disposed += delegate { _fileExplorer.Show(); };
            progressForm.Show(this);
        }