Пример #1
0
        /// <summary>
        /// Extract files from a zip file.
        /// </summary>
        /// <param name="cmdOptions">The zip program command line arguments.</param>
        /// <param name="zipFilePath">The file path of the zip file from which to extract files.</param>
        /// <param name="outputDirectoryPath">The path where you want to put the extracted files.</param>
        public bool UnzipFile(string cmdOptions, string zipFilePath, string outputDirectoryPath)
        {
            // Verify input file and output path have been specified
            if (string.IsNullOrEmpty(m_ZipProgramPath) || string.IsNullOrEmpty(m_WorkDir))
            {
                var msg = "Zip program path and/or working path not specified";
#pragma warning disable 618
                m_EventLogger?.PostEntry(msg, logMsgType.logError, true);
#pragma warning restore 618
                m_Logger?.Error(msg);

                return(false);
            }

            // Verify input file exists
            if (!File.Exists(zipFilePath))
            {
                var msg = "Input file not found: " + zipFilePath;
#pragma warning disable 618
                m_EventLogger?.PostEntry(msg, logMsgType.logError, true);
#pragma warning restore 618
                m_Logger?.Error(msg);

                return(false);
            }

            // Verify output path exists
            if (!Directory.Exists(outputDirectoryPath))
            {
                var msg = "Output directory " + outputDirectoryPath + " does not exist";
#pragma warning disable 618
                m_EventLogger?.PostEntry(msg, logMsgType.logError, true);
#pragma warning restore 618
                m_Logger?.Error(msg);

                return(false);
            }

            // Setup the unzip program
            var zipper = new ProgRunner
            {
                Arguments          = "-Extract " + cmdOptions + " \"" + zipFilePath + "\" \"" + outputDirectoryPath + "\"",
                MonitoringInterval = m_WaitInterval,
                Name              = "Zipper",
                Program           = m_ZipProgramPath,
                WorkDir           = m_WorkDir,
                Repeat            = false,
                RepeatHoldOffTime = 0,
                CreateNoWindow    = m_CreateNoWindow,
                WindowStyle       = m_WindowStyle,
            };

            // Start the unzip program
            zipper.StartAndMonitorProgram();

            // Wait for zipper program to complete
            var success = WaitForZipProgram(zipper);

            return(success);
        }
Пример #2
0
        /// <summary>
        /// Create a zip file.
        /// </summary>
        /// <param name="cmdOptions">The zip program command line arguments.</param>
        /// <param name="outputFile">The file path of the output zip file.</param>
        /// <param name="inputSpec">The files and/or directories to archive.</param>
        public bool MakeZipFile(string cmdOptions, string outputFile, string inputSpec)
        {
            // Verify input file and output path have been specified
            if (string.IsNullOrEmpty(m_ZipProgramPath) || string.IsNullOrEmpty(m_WorkDir))
            {
                var msg = "Zip program path and/or working path not specified";
#pragma warning disable 618
                m_EventLogger?.PostEntry(msg, logMsgType.logError, true);
#pragma warning restore 618
                m_Logger?.Error(msg);

                return(false);
            }

            // Setup the zip program
            var zipper = new ProgRunner
            {
                Arguments          = "-Add " + cmdOptions + " \"" + outputFile + "\" \"" + inputSpec + "\"",
                Program            = m_ZipProgramPath,
                WorkDir            = m_WorkDir,
                MonitoringInterval = m_WaitInterval,
                Name              = "Zipper",
                Repeat            = false,
                RepeatHoldOffTime = 0,
                CreateNoWindow    = m_CreateNoWindow
            };

            // Start the zip program
            zipper.StartAndMonitorProgram();

            // Wait for zipper program to complete
            var success = WaitForZipProgram(zipper);

            return(success);
        }