Example #1
0
 private static void AskTryAgain(InstallMod op, string title, string msg)
 {
     isInstalling = false;
     dlRetry = true;
     notifier.NotifyTryAgain(title, msg,
         () => InstallMod(op), //try again
         () => //cancel
         {
             dlRetry = false;
             log.Info("User don't want to try again");
         },
         () => //download manually
         {
             dlRetry = false;
             log.Info("Downloading mod manually");
             Process.Start(op.url);
         });
 }
Example #2
0
        /// <summary>
        /// Pipe a zip download directly through the decompressor
        /// </summary>
        private static bool UnzipWithTemp(InstallMod op, Stream zipStream, string outFolder)
        {
            try
            {
                string tempFolder = Path.Combine(outFolder, "temp");
                UnZip.unzipFromStream(zipStream, tempFolder);
            }
            catch (Exception ex)
            {
                log.Error("Error extracting files. Downloaded archive is possibly corrupt." , ex);
                if (op != null)
                    AskTryAgain(op, "Error Extracting Files", "Downloaded archive is possibly corrupt");
                return false;
            }

            try
            {
                foreach (var file in Directory.EnumerateFiles(Path.Combine(outFolder, "temp"), "*", System.IO.SearchOption.AllDirectories))
                {
                    string destinationPath = Path.Combine(outFolder, file.Substring(outFolder.Length + 6, file.Length - outFolder.Length - 6));
                    if (!Directory.Exists(Path.GetDirectoryName(destinationPath)))
                        Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));
                    File.Move(file, destinationPath);
                }
                if (Directory.Exists(Path.Combine(outFolder, "temp")))
                    Directory.Delete(Path.Combine(outFolder, "temp"), true);

                return true;
            }
            catch (Exception ex)
            {
                log.Error("Error moving extracted files from temporary folder.", ex);
                if (op != null)
                    AskTryAgain(op, "Error Installing Mod", "Error moving extracted files from temporary folder");
            }

            return false;
        }