コード例 #1
0
        private void ReadInputFileWorker(object sender, DoWorkEventArgs e)
        {
            var list = new List <TreeNode>();

            try
            {
                m_tmpUnpackedOutputPathForUi = m_ku.GetTempPath();
                m_remapInfo = m_ku.Unpack(e.Argument.ToString(), m_tmpUnpackedOutputPathForUi);
                foreach (var keyValuePair in m_remapInfo)
                {
                    if (File.Exists(keyValuePair.Key))
                    {
                        var text = keyValuePair.Value.Replace(m_tmpUnpackedOutputPathForUi, "");
                        if (text.StartsWith(Path.DirectorySeparatorChar.ToString()))
                        {
                            text = text.Substring(1);
                        }
                        list.Add(new TreeNode(text)
                        {
                            Checked = true,
                            Tag     = keyValuePair
                        });
                    }
                }
                list.Sort((t1, t2) => t1.Text.CompareTo(t2.Text));
            }
            catch (Exception ex)
            {
                e.Result = ex;
                return;
            }
            e.Result = list;
        }
コード例 #2
0
        /// <summary>
        /// Starts the Unitypackage Unpacker. Unpacks package, registers or unregisters shell handler.
        /// </summary>
        internal void Start()
        {
            if (string.IsNullOrEmpty(InputFile) && !Register && !Unregister)
            {
                Console.WriteLine(GetUsage());
                Environment.Exit(1);
            }

            // if input file is given, but does not exists, exit with error
            if (!string.IsNullOrEmpty(InputFile) && !File.Exists(InputFile))
            {
                Console.WriteLine("File not found: " + InputFile);
                Console.WriteLine(GetUsage());
                Environment.Exit(2);
            }

            // If inputfile is set, we want to unpack something.
            // If its not set, we propably just want to un/register the shell handler
            if (!string.IsNullOrEmpty(InputFile))
            {
                var inputFileInfo = new FileInfo(InputFile);

                // If output path is not set, define a standard, which is <inputfilepath_unpacked>
                if (OutputPath == null)
                {
                    OutputPath = Path.Combine(inputFileInfo.Directory.FullName, inputFileInfo.Name + "_unpacked");
                }

                // If output path already exists, find an alternative!
                if (Directory.Exists(OutputPath))
                {
                    int appendix = 2;
                    while (true)
                    {
                        var newOutputPath = Path.Combine(inputFileInfo.Directory.FullName,
                                                         inputFileInfo.Name + "_unpacked (" + appendix + ")");

                        if (!Directory.Exists(newOutputPath))
                        {
                            Directory.CreateDirectory(newOutputPath);
                            OutputPath = newOutputPath;
                            break;
                        }
                        appendix++;
                    }
                }
            }

            // TODO 2: Add selective deselection via UI
            var u = new KISSUnpacker();

            try
            {
                if (Register)
                {
                    u.RegisterDefaultShellHandler();
                }
                else if (Unregister)
                {
                    u.UnregisterDefaultShellHandler();
                }
            }
            catch (UnauthorizedAccessException e)
            {
                if (Register)
                {
                    Console.WriteLine("Error: UnauthorizedAccessException. Cannot register explorer context menu handler!");
                }
                if (Unregister)
                {
                    Console.WriteLine("Error: UnauthorizedAccessException. Cannot register explorer context menu handler!");
                }
            }

            try
            {
                if (InputFile != null)
                {
                    u.Unpack(InputFile, OutputPath);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("==========================================");
                Console.WriteLine(e);
                Console.WriteLine("==========================================");

                if (Environment.UserInteractive)
                {
                    Console.WriteLine("An error occured (see above)!. Press a key to continue...");
                    Console.ReadLine();
                }
            }
        }