예제 #1
0
파일: PackRat.cs 프로젝트: Mashrien/PackRat
        /// <summary>
        /// Primary entry point
        /// </summary>
        public Archive()
        {
            Log("Initializing PRX manager", LogType.Init);

            Utils.InitDriveInfo();

            ErrCode initErr = ErrCode.NULL;

            initErr = SetTempFile();

            Log("Creating root node", LogType.Info);
            RootNode  = PRNode.CreateRootNode();
            FileTable = new PRTable();

            PackRatUI.Program.Archive = this;

            MasterFileTable = FileTable;

            if (initErr > ErrCode.SUCCESS)
            {
                Error(initErr);
                if (initErr.HasFlag(ErrCode.EX_ACCESS_DENIED))
                {
                    System.Windows.Forms.MessageBox.Show("ERR_ACCESS_DENIED" + Environment.NewLine + "Please try running as Administrator.");
                    Environment.Exit(0);
                }
            }
        }
예제 #2
0
        //CURRENT Move this to PackRat.cs - Doesn't belong in the UI
        //TODO Why is this in the UI? Needs to be moved to PackRat.cs
        //private void ExtractRecurse(PRTableNode tn, string outPath) {
        //    DirectoryInfo di = Directory.CreateDirectory(outPath + tn.Name);
        //    outPath = di.FullName + @"\";

        //    foreach (PRTableNode prtn in PRX.GetChildren(tn.GUID)) {
        //        if (prtn.Flags.HasFlag(NodeFlag.File)) {
        //            FileInfo fi = new FileInfo(outPath + prtn.Name);
        //            Log($"EXFil: {prtn.GUID} => {fi.Directory}", LogType.IO);
        //            PRX.ExtractFile(prtn.Node, fi.Directory, fi.Name);
        //            }

        //        if (prtn.Flags.HasFlag(NodeFlag.Directory)) {
        //            Log($"EXDir: {prtn.GUID} => {outPath}", LogType.IO);
        //            ExtractRecurse(prtn, outPath);
        //            }

        //        }

        //    }

        private void bExtract_Click(object sender, EventArgs e)
        {
            if (objectListView1.SelectedObjects.Count == 1)
            {
                //    Log("Multiple items selected, aborting", LogType.Warning);
                //    return;
                //    }
                PRTableNode selObject = (PRTableNode)objectListView1.SelectedObject;
                if (selObject == null)
                {
                    return;
                }

                ProgressTracker pt = new ProgressTracker();
                Log($"Extract: {selObject.Name}", LogType.Info);
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.FileName         = selObject.DisplayName;
                sfd.InitialDirectory = saveState.LastDirectory.FullName;

                if (selObject.Node.Flags.HasFlag(NodeFlag.Directory))
                {
                    FolderBrowserDialog fbd = new FolderBrowserDialog();
                    fbd.ShowNewFolderButton = true;
                    //TODO Store previously selected directory
                    fbd.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                    DialogResult fbdres = fbd.ShowDialog();
                    if (fbdres == DialogResult.OK || fbdres == DialogResult.Yes)
                    {
                        Log($"Selected \"{fbd.SelectedPath}\" for output", LogType.IO);
                        //ExtractRecurse(selObject, fbd.SelectedPath);
                        PRX.Extract(selObject.Node, new DirectoryInfo(fbd.SelectedPath), out pt);
                    }
                    return;
                }


                DialogResult res = sfd.ShowDialog();
                if (res == DialogResult.OK || res == DialogResult.Yes)
                {
                    FileInfo fi     = new FileInfo(sfd.FileName);
                    ErrCode  result = HasPermission(fi.Directory.FullName);
                    if (!result.HasFlag(ErrCode.SUCCESS))
                    {
                        Log($"Extract Failed: {result}", LogType.Error);
                        MessageBox.Show($"Failed to extract {Environment.NewLine}{fi.Directory.FullName} : {result}");
                        return;
                    }
                    // extract file to target dir
                    Log($"EX: {selObject.GUID} => {fi.Directory}", LogType.IO);
                    PRX.Extract(selObject.Node, fi.Directory, out pt, sfd.FileName);
                }
            }
            else if (objectListView1.SelectedObjects.Count > 1)
            {
                ProgressTracker pt = new ProgressTracker();
                Log($"Extract: Multiple", LogType.Info);

                FolderBrowserDialog fbd = new FolderBrowserDialog();
                fbd.ShowNewFolderButton = true;
                //TODO Store previously selected directory
                fbd.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                DialogResult fbdres = fbd.ShowDialog();
                if (fbdres == DialogResult.OK || fbdres == DialogResult.Yes)
                {
                    Log($"Selected \"{fbd.SelectedPath}\" for output", LogType.IO);
                    foreach (PRTableNode selObject in objectListView1.SelectedObjects)
                    {
                        PRX.Extract(selObject.Node, new DirectoryInfo(fbd.SelectedPath), out pt);
                    }
                }
                return;
            }
        }