コード例 #1
0
 public MainWindow()
 {
     InitializeComponent();
     saveToFolderDialog = new FolderBrowserDialog();
     openFileDialog     = new OpenFileDialog();
     m_ku  = new KISSUnpacker();
     m_upu = new UpuConsole();
     m_shellHandlerCheckTimer          = new Timer();
     m_shellHandlerCheckTimer.Interval = 5000;
     m_shellHandlerCheckTimer.Tick    += ShellHandlerCheckTimer_Tick;
     m_shellHandlerCheckTimer.Enabled  = true;
     m_shellHandlerCheckTimer.Start();
     ShellHandlerCheckTimer_Tick(null, EventArgs.Empty);
 }
コード例 #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();
                }
            }
        }