当前位置: 首页>>代码示例>>C#>>正文


C# Package.ExtractAll方法代码示例

本文整理汇总了C#中Package.ExtractAll方法的典型用法代码示例。如果您正苦于以下问题:C# Package.ExtractAll方法的具体用法?C# Package.ExtractAll怎么用?C# Package.ExtractAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Package的用法示例。


在下文中一共展示了Package.ExtractAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            #region wait for running instance to exit

            do
            {
                bool createdNewMutex;

                Mutex app = new Mutex(true, args[0], out createdNewMutex);

                app.Dispose();

                if (createdNewMutex)
                    break;

                Thread.Sleep(1000);
            }
            while (true);

            #endregion

            try
            {
                string pkgFile;

                switch (Environment.OSVersion.Platform)
                {
                    case PlatformID.Win32NT:
                        pkgFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "").Replace("/", "\\")), "update.pkg");
                        break;

                    case PlatformID.Unix:
                        pkgFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Replace("file://", "")), "update.pkg");
                        break;

                    default:
                        throw new Exception("Platform not supported.");
                }

                using (Package package = new Package(pkgFile, PackageMode.Open))
                {
                    package.ExtractAll(ExtractLocation.Custom, args[1], true);
                }

                MessageBox.Show("Update was installed successfully. Click OK to continue.", "Update Installed - Technitium Automatic Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occured while updating application:\r\n\r\n" + ex.Message + "\r\n\r\nChanges were automatically rolled back.", "Update Error - Technitium Automatic Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
开发者ID:rodoviario,项目名称:BitChatClient,代码行数:54,代码来源:Program.cs

示例2: DownloadAndInstallAsync

        private void DownloadAndInstallAsync()
        {
            bool exitApp = false;

            try
            {
                string tmpGZFile = Path.GetTempFileName();
                string tmpPkgFile = Path.GetTempFileName();
                string tmpFolder;

                do
                {
                    tmpFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                } while (Directory.Exists(tmpFolder));

                Directory.CreateDirectory(tmpFolder);

                try
                {
                    #region download update file

                    using (WebClient client = new WebClient())
                    {
                        client.Headers.Add("User-Agent", GetUserAgent());
                        client.DownloadFile(_updateInfo.DownloadURI, tmpGZFile);
                    }

                    #endregion

                    #region verify signature, extract & execute

                    using (FileStream sGZ = new FileStream(tmpGZFile, FileMode.Open, FileAccess.Read))
                    {
                        //verify signature
                        if (!_updateInfo.DownloadSignature.Verify(sGZ, _trustedRootCAs))
                            throw new Exception("Update file signature does not match.");

                        using (FileStream sPkg = new FileStream(tmpPkgFile, FileMode.Create, FileAccess.ReadWrite))
                        {
                            //unzip
                            sGZ.Position = 0;
                            using (GZipStream unzip = new GZipStream(sGZ, CompressionMode.Decompress, true))
                            {
                                unzip.CopyTo(sPkg);
                            }

                            //extract
                            sPkg.Position = 0;
                            Package updatePackage = new Package(sPkg, PackageMode.Open);
                            updatePackage.ExtractAll(ExtractLocation.Custom, tmpFolder, true);

                            //execute
                            switch (Environment.OSVersion.Platform)
                            {
                                case PlatformID.Win32NT:
                                    {
                                        string appFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "").Replace("/", "\\"));

                                        ProcessStartInfo pInfo = new ProcessStartInfo(Path.Combine(tmpFolder, "update.exe"), "\"" + _mutexName + "\" \"" + appFolder + "\"");
                                        pInfo.UseShellExecute = true;
                                        pInfo.Verb = "runas";

                                        Process.Start(pInfo);
                                    }
                                    break;

                                case PlatformID.Unix:
                                    {
                                        string appFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Replace("file://", ""));

                                        ProcessStartInfo pInfo = new ProcessStartInfo("mono", "\"" + Path.Combine(tmpFolder, "update.exe") + "\" \"" + _mutexName + "\" \"" + appFolder + "\"");
                                        pInfo.UseShellExecute = false;

                                        Process.Start(pInfo);
                                    }
                                    break;

                                default:
                                    throw new Exception("Platform not supported.");
                            }

                            exitApp = true;
                        }
                    }

                    #endregion
                }
                finally
                {
                    File.Delete(tmpGZFile);
                    File.Delete(tmpPkgFile);
                }
            }
            catch (Exception ex)
            {
                RaiseEventUpdateError(ex);
            }

            _downloadInstall = null;

//.........这里部分代码省略.........
开发者ID:rodoviario,项目名称:BitChatClient,代码行数:101,代码来源:AutomaticUpdateClient.cs


注:本文中的Package.ExtractAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。