コード例 #1
0
 public static Task <ModuleInstalltionResult> InstallModule(string modZipFile, string modulesFolder)
 {
     return(Task.Run(() =>
     {
         try
         {
             DirectoryInfo dest = new DirectoryInfo(modulesFolder);
             FileInfo source = new FileInfo(modZipFile);
             if (!source.Exists)
             {
                 return ModuleInstalltionResult.FAILED;
             }
             try
             {
                 if (!dest.Exists)
                 {
                     dest.Create();
                 }
             }
             catch (Exception)
             {
                 return ModuleInstalltionResult.FAILED_DEST;
             }
             UtilsGeneral.extractZipSerial(new FileInfo(modZipFile), new DirectoryInfo(modulesFolder));
             return ModuleInstalltionResult.OK;
         }
         catch (Exception)
         {
             return ModuleInstalltionResult.FAILED;
         }
     }));
 }
コード例 #2
0
        public async Task <RocketModInstallationCompletedType> Install(bool clean = false)
        {
            var task = Task.Run(() =>
            {
                try
                {
                    bool updateAvailable = IsUpdateAvailable().Result;
                    if (clean | updateAvailable)
                    {
                        string v = GetServerVersion().Result;
                        try
                        {
                            string tmpFile = gamedir.FullName + "\\rocketmod.tmp";

                            ManualResetEvent waitInstallCompleted = new ManualResetEvent(false);

                            bool failed = false;
                            UniversalWebClient client     = new UniversalWebClient();
                            client.DownloadFileCompleted += (sender, e) =>
                            {
                                try
                                {
                                    FileInfo info = new FileInfo(tmpFile);
                                    if (info.Length > 0)
                                    {
                                        UtilsGeneral.extractZipSerial(info, gamedir);
                                        LocalVersion = v;
                                    }
                                    else
                                    {
                                        failed = true;
                                    }
                                }
                                catch (Exception)
                                {
                                    failed = true;
                                }

                                waitInstallCompleted.Set();
                            };



                            if (File.Exists(tmpFile))
                            {
                                File.Delete(tmpFile);
                            }
                            client.DownloadFileAsync(downloadAddr, tmpFile);


                            waitInstallCompleted.WaitOne();

                            if (failed)
                            {
                                RocketInstallationCompleted?.Invoke(this, RocketModInstallationCompletedType.FailedUnknownException);
                                return(RocketModInstallationCompletedType.FailedUnknownException);
                            }
                            else
                            {
                                RocketInstallationCompleted?.Invoke(this, RocketModInstallationCompletedType.Success);
                                return(RocketModInstallationCompletedType.Success);
                            }
                        }
                        catch (Exception)
                        {
                            RocketInstallationCompleted?.Invoke(this, RocketModInstallationCompletedType.FailedNoInternetAccessOrNoIOPermissions);
                            return(RocketModInstallationCompletedType.FailedNoInternetAccessOrNoIOPermissions);
                        }
                    }
                    else
                    {
                        RocketInstallationCompleted?.Invoke(this, RocketModInstallationCompletedType.Success);
                        return(RocketModInstallationCompletedType.Success);
                    }
                }
                catch (Exception)
                {
                    RocketInstallationCompleted?.Invoke(this, RocketModInstallationCompletedType.FailedUnknownException);
                    return(RocketModInstallationCompletedType.FailedUnknownException);
                }
            });

            return(await task);
        }