Exemplo n.º 1
0
        public static async Task <bool> Run(string url, string _destDir, bool overwrite = false)
        {
            var inst = new Installer(_destDir);

            return(await Task.Run(() =>
            {
                var result = false;
                var archivePath = Path.Combine(inst._tempDir, "update.7z");
                var dlResult = true;

                // Only try to download URLs. We can skip this step for local files.
                if (File.Exists(url))
                {
                    archivePath = url;
                }
                else
                {
                    dlResult = inst.Download(url, archivePath);
                }

                if (dlResult && inst.Extract(archivePath))
                {
                    result = overwrite ? inst.InstallOverwrite() : inst.InstallReplace();
                    inst.Cleanup();

                    if (result)
                    {
                        inst.Display.Close();
                    }
                }

                return result;
            }));
        }
Exemplo n.º 2
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");

            return(await Task.Run(() =>
            {
                if (inst.Download("https://aka.ms/vs/16/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("vcruntime140.dll") == 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("vcruntime140.dll") != IntPtr.Zero)
                    {
                        inst.Display.Close();
                        return true;
                    }
                    else
                    {
                        inst.Display.UpdateStatus(1, Resources.StatusError);
                        inst.Display.Log(Resources.LogInstallerFailed);
                        return false;
                    }
                }

                return false;
            }));
        }
Exemplo n.º 3
0
        public static async Task <bool> InstallMsvcrt()
        {
            var inst    = new Installer(Path.GetTempPath());
            var exePath = Path.Combine(inst._tempDir, "vc_redist.x64.exe");

            return(await Task.Run(async() =>
            {
                if (await inst.Download("https://aka.ms/vs/16/release/VC_redist.x64.exe", exePath))
                {
                    inst._display.UpdateStatus(0, "[2/2]: Launching installer...");
                    inst._display.Log("Launching installer...");

                    try
                    {
                        var proc = Process.Start(exePath);
                        proc.WaitForExit();
                        proc.Close();
                    } catch (System.ComponentModel.Win32Exception ex)
                    {
                        inst._display.Log($"Failed to launch installer: {ex.Message}");
                        inst._display.Log("Trying again...");

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

                        var cancel = inst._display.GetCancelToken();

                        inst._display.Log("Waiting for installer to exit...");
                        while (!File.Exists("C:\\Windows\\system32\\msvcp140.dll") && !cancel.IsCancellationRequested)
                        {
                            Thread.Sleep(500);
                        }

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

                    inst.Cleanup();
                    return File.Exists("C:\\Windows\\system32\\msvcp140.dll");
                }

                return false;
            }));
        }
Exemplo n.º 4
0
        public static async Task <bool> Run(string url, string destDir, string tmpName, int stripDirs = 0, bool overwrite = false)
        {
            var inst = new Installer(destDir, tmpName);

            return(await Task.Run(() =>
            {
                inst._display.Log("正在准备下载【悬浮窗插件】的组件,此窗口会出现3次,请等待下载窗口全部消失后再重启 ACT。");
                inst._display.Log("本【悬浮窗插件】是 cactbot 的必备组件。");
                inst._display.Log("--------------");
                var scVersion = Assembly.Load("SharpCompress").GetName().Version;
                if (scVersion < Version.Parse("0.24.0"))
                {
                    inst._display.Log("请先卸载 WS 悬浮窗插件!本插件可完全取代 WS 悬浮窗插件。");
                    inst._display.UpdateStatus(0, Resources.StatusError);
                    return false;
                }

                var result = false;
                var archivePath = Path.Combine(inst.TempDir, "update.file");
                var dlResult = true;

                // Only try to download URLs. We can skip this step for local files.
                if (File.Exists(url))
                {
                    archivePath = url;
                }
                else
                {
                    dlResult = inst.Download(url, archivePath);
                }

                if (dlResult && inst.Extract(archivePath, stripDirs))
                {
                    result = overwrite ? inst.InstallOverwrite() : inst.InstallReplace();
                    inst.Cleanup();

                    if (result)
                    {
                        inst.Display.Close();
                    }
                }

                return result;
            }));
        }
Exemplo n.º 5
0
        public static async Task <bool> Run(string url, string destDir, string tmpName, int stripDirs = 0, bool overwrite = false)
        {
            var inst = new Installer(destDir, tmpName);

            return(await Task.Run(() =>
            {
                var scVersion = Assembly.Load("SharpCompress").GetName().Version;
                inst._display.Log("Current SharpCompress version: " + scVersion.ToString());
                if (scVersion < Version.Parse("0.21.1"))
                {
                    inst._display.Log(Resources.SharpCompressOutdatedError);
                    inst._display.UpdateStatus(0, Resources.StatusError);
                    return false;
                }

                var result = false;
                var archivePath = Path.Combine(inst.TempDir, "update.file");
                var dlResult = true;

                // Only try to download URLs. We can skip this step for local files.
                if (File.Exists(url))
                {
                    archivePath = url;
                }
                else
                {
                    dlResult = inst.Download(url, archivePath);
                }

                if (dlResult && inst.Extract(archivePath, stripDirs))
                {
                    result = overwrite ? inst.InstallOverwrite() : inst.InstallReplace();
                    inst.Cleanup();

                    if (result)
                    {
                        inst.Display.Close();
                    }
                }

                return result;
            }));
        }
Exemplo n.º 6
0
        public static async Task <bool> Run(string url, string _destDir, bool overwrite = false)
        {
            var inst = new Installer(_destDir);

            return(await Task.Run(() =>
            {
                var result = false;
                var archivePath = Path.Combine(inst._tempDir, "update.7z");

                if (inst.Download(url, archivePath) && inst.Extract(archivePath))
                {
                    result = overwrite ? inst.InstallOverwrite() : inst.InstallReplace();
                    inst.Cleanup();

                    if (result)
                    {
                        inst.Display.Close();
                    }
                }

                return result;
            }));
        }
Exemplo n.º 7
0
        public static async Task <bool> Run(string url, string _destDir, bool overwrite = false)
        {
            var inst = new Installer(_destDir);

            // We need to use a Task here since parts of Download() and the other methods are blocking.
            return(await Task.Run(async() =>
            {
                var result = false;
                var archivePath = Path.Combine(inst._tempDir, "update.7z");

                if (await inst.Download(url, archivePath) && inst.Extract(archivePath))
                {
                    result = overwrite ? inst.InstallOverwrite() : inst.InstallReplace();
                    inst.Cleanup();

                    if (result)
                    {
                        inst.Display.Close();
                    }
                }

                return result;
            }));
        }