public static async Task <bool> DownloadAndExtractTo(Installer inst, string url, string tmpName, string destDir, string archiveDir, string message, string archiveDir2 = null)
        {
            return(await Task.Run(() =>
            {
                inst._display.Log($"正在准备下载【悬浮窗插件】的组件,{message},请等待下载窗口全部消失后再重启 ACT。");
                inst._display.Log("本【悬浮窗插件】是 cactbot 的必备组件。");
                inst._display.Log("如果遇到问题,请尝试【重启ACT】或者【重启电脑】并【关闭杀毒软件】再试。");
                inst._display.Log("--------------");

                var temp = Path.Combine(inst.TempDir, "archive.tmp");
                inst.Download(url, temp, true);
                inst._display.Log("正在解压文件,请稍候……");

                using (var archive = ArchiveFactory.Open(temp))
                {
                    var options = new SharpCompress.Common.ExtractionOptions()
                    {
                        Overwrite = true
                    };
                    var entries = archive.Entries.Where(x => x.Key.StartsWith(archiveDir) && !x.IsDirectory);
                    foreach (var entry in entries)
                    {
                        var filename = Path.Combine(destDir, entry.Key.Substring(archiveDir.Length));
                        var fileInfo = new FileInfo(filename);
                        fileInfo.Directory.Create();
                        try
                        {
                            entry.WriteToFile(fileInfo.FullName, options);
                        }
                        catch (Exception e)
                        {
                            entry.WriteToFile(fileInfo.FullName + ".cafestoreupdate", options);
                        }
                    }
                }

                if (archiveDir2 != null)
                {
                    using (var archive = ArchiveFactory.Open(temp))
                    {
                        var options = new SharpCompress.Common.ExtractionOptions()
                        {
                            Overwrite = true
                        };
                        var entries = archive.Entries.Where(x => x.Key.StartsWith(archiveDir2) && !x.IsDirectory);
                        foreach (var entry in entries)
                        {
                            var filename = Path.Combine(destDir, entry.Key.Substring(archiveDir2.Length));
                            var fileInfo = new FileInfo(filename);
                            fileInfo.Directory.Create();
                            try
                            {
                                entry.WriteToFile(fileInfo.FullName, options);
                            }
                            catch (Exception e)
                            {
                                entry.WriteToFile(fileInfo.FullName + ".cafestoreupdate", options);
                            }
                        }
                    }
                }

                inst._display.Log("正在删除临时文件,请稍候……");
                try
                {
                    File.Delete(tmpName);
                }
                catch (Exception e)
                {
                    // do nothing
                }

                inst._display.Log("处理完成。");
                inst._display.Close();

                return true;
            }));
        }
Exemple #2
0
        public static async Task <bool> InstallCef(string cefPath)
        {
            var lib = IntPtr.Zero;

            while (true)
            {
                lib = NativeMethods.LoadLibrary("msvcp140.dll");
                if (lib != IntPtr.Zero)
                {
                    NativeMethods.FreeLibrary(lib);
                    break;
                }

                var response = MessageBox.Show(
                    Resources.MsvcrtMissing,
                    Resources.OverlayPluginTitle,
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question
                    );

                if (response == DialogResult.Yes)
                {
                    var installed = await Installer.InstallMsvcrt();

                    if (!installed)
                    {
                        MessageBox.Show(
                            Resources.MsvcrtFailed,
                            Resources.OverlayPluginTitle,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error
                            );
                    }
                }
                else
                {
                    return(false);
                }
            }

            var url = CEF_DL.Replace("{CEF_VERSION}", CEF_VERSION).Replace("{ARCH}", Environment.Is64BitProcess ? "x64" : "x86");

            var result = await Installer.Run(url, cefPath);

            if (!result || !Directory.Exists(cefPath))
            {
                var response = MessageBox.Show(
                    Resources.UpdateCefDlFailed,
                    Resources.ErrorTitle,
                    MessageBoxButtons.YesNo
                    );

                if (response == DialogResult.Yes)
                {
                    return(await InstallCef(cefPath));
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                File.WriteAllText(Path.Combine(cefPath, "version.txt"), CEF_VERSION);
                return(true);
            }
        }
        public static async Task <bool> DownloadAndExtractTo(string url, string tmpName, string destDir, string archiveDir, string message, string archiveDir2 = null)
        {
            var inst = new Installer(destDir, tmpName);

            return(await DownloadAndExtractTo(inst, tmpName, destDir, archiveDir, message, archiveDir2));
        }
Exemple #4
0
        public static async Task <bool> InstallMsvcrt()
        {
            var inst    = new Installer(Path.Combine(Path.GetTempPath(), "OverlayPlugin.tmp"), "msvcrt");
            var exePath = Path.Combine(inst.TempDir, "vc_redist.x64.exe");

            var libname = Environment.Is64BitProcess ? "vcruntime140_1.dll" : "vcruntime140.dll";

            return(await Task.Run(() =>
            {
                if (inst.Download("https://aka.ms/vs/17/release/vc_redist.x64.exe", exePath, true))
                {
                    inst.Display.UpdateStatus(0, string.Format(Resources.StatusLaunchingInstaller, 2, 2));
                    inst.Display.Log(Resources.LogLaunchingInstaller);

                    try
                    {
                        var proc = Process.Start(exePath);
                        proc.WaitForExit();
                        proc.Close();
                    }
                    catch (System.ComponentModel.Win32Exception ex)
                    {
                        inst.Display.Log(string.Format(Resources.LaunchingInstallerFailed, ex.Message));
                        inst.Display.Log(Resources.LogRetry);

                        using (var proc = new Process())
                        {
                            proc.StartInfo.FileName = exePath;
                            proc.StartInfo.UseShellExecute = true;
                            proc.Start();
                        }

                        var cancel = inst.Display.GetCancelToken();

                        inst.Display.Log(Resources.LogInstallerWaiting);
                        while (NativeMethods.LoadLibrary(libname) == IntPtr.Zero && !cancel.IsCancellationRequested)
                        {
                            Thread.Sleep(500);
                        }

                        // Wait some more just to be sure that the installer is done.
                        Thread.Sleep(1000);
                    }

                    inst.Cleanup();
                    if (NativeMethods.LoadLibrary(libname) != IntPtr.Zero)
                    {
                        inst.Display.Close();
                        return true;
                    }
                    else
                    {
                        inst.Display.UpdateStatus(1, Resources.StatusError);
                        inst.Display.Log(Resources.LogInstallerFailed);
                        return false;
                    }
                }

                return false;
            }));
        }