Exemple #1
0
        /// <summary>
        /// </summary>
        /// <param name=""></param>
        private bool Install(BuildLaunchMode Mode)
        {
            string ResultMessage = "";
            bool   Success       = true;

            using (ProgressForm form = new ProgressForm())
            {
                ScriptBuildProgressDelegate Callback = (string InState, float InProgress) =>
                {
                    form.SetProgress(InState, InProgress);
                };

                Task work = Task.Run(
                    () =>
                {
                    Success = Mode.Install(Downloader.LocalFolder, ref ResultMessage, Callback);
                    if (Success)
                    {
                        Downloader.Installed = true;
                    }
                }
                    );

                form.Work = work;
                form.ShowDialog();

                if (!Success)
                {
                    MessageBox.Show("Failed to start install executable with error:\n\n" + ResultMessage, "Install Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            return(Success);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="Action"></param>
        private void RunAction(RemoteActionClientState Action, CancellationToken CancelToken)
        {
            // TODO: we should figure out how to handle cancellation for installs, not sure the safest way to do this though hum.

            switch (Action.Type)
            {
            case RemoteActionType.Install:
            {
                Guid   ManifestId      = Guid.Parse(Action.Settings["ManifestId"]);
                string DeviceName      = Action.Settings["DeviceName"];
                string InstallLocation = Action.Settings["InstallLocation"];

                ScriptBuildProgressDelegate Callback = (string InState, float InProgress) =>
                {
                    if (Action.Progress != InProgress || Action.ProgressText != InState)
                    {
                        Action.Progress     = InProgress;
                        Action.ProgressText = InState;
                        Action.Dirty        = true;
                    }
                };

                DownloadManager.BlockDownload(ManifestId);
                try
                {
                    if (DownloadManager.PerformInstallation(ManifestId, DeviceName, InstallLocation, Callback))
                    {
                        Action.Failed    = false;
                        Action.Completed = true;
                        Action.Dirty     = true;
                    }
                    else
                    {
                        Action.ResultMessage = "Failed with generic error.";
                        Action.Failed        = true;
                        Action.Completed     = true;
                        Action.Dirty         = true;
                    }
                }
                catch (Exception Ex)
                {
                    Logger.Log(LogLevel.Error, LogCategory.Manifest, "Failed to install with error: {0}", Ex.Message);

                    Action.ResultMessage = Ex.Message;
                    Action.Failed        = true;
                    Action.Completed     = true;
                    Action.Dirty         = true;
                }
                finally
                {
                    DownloadManager.UnblockDownload(ManifestId);
                }

                break;
            }
            }
        }
Exemple #3
0
        /// <summary>
        /// </summary>
        public bool Install(string LocalFolder, ref string ResultMessage, ScriptBuildProgressDelegate Callback)
        {
            if (ScriptInstance != null)
            {
                CopyArgumentsToScript();

                ScriptBuild Build = MakeScriptBuild();
                Build.ProgressCallback = Callback;

                if (!ScriptInstance.Install(Build))
                {
                    if (Build.ErrorMessage == "")
                    {
                        ResultMessage = "Script failed to install, check console output window for details.";
                    }
                    else
                    {
                        ResultMessage = Build.ErrorMessage;
                    }
                    return(false);
                }

                return(true);
            }
            else
            {
                if (InstallSteps.Count == 0)
                {
                    return(true);
                }

                foreach (BuildInstallStep Step in InstallSteps)
                {
                    if (!InstallStep(LocalFolder, ref ResultMessage, Step))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Archive"></param>
        /// <param name="OutputFolder"></param>
        /// <returns></returns>
        public static bool UnpackArchive(string ArchivePath, string OutputFolder, ScriptBuildProgressDelegate ProgressCallback = null)
        {
            string installLocation = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            string sevenZipPath    = Path.Combine(Path.Combine(Path.Combine(installLocation, "Libraries"), "7zip"), "7za.exe");

            ProgressParser Parser = new ProgressParser();

            Parser.ParsePartialLines = false;
            Parser.LineSeperator     = "\r";
            Parser.AddPattern(@"^\s+(\d+)\% \- (.+)$",
                              new ProgressMatch(ProgressMatchType.Progress, ProgressMatchFormat.Float, 100),
                              new ProgressMatch(ProgressMatchType.CurrentFileName, ProgressMatchFormat.String));

            ScriptBuildOutputCallbackDelegate OutputCallback = (string Line) =>
            {
                Parser.Parse(Line);
                ProgressCallback?.Invoke("Decompressing " + Parser.CurrentFileName + "...", Parser.Progress);
            };

            int exitCode = RunAndWait(sevenZipPath, installLocation, "x \"" + ArchivePath + "\" -o\"" + OutputFolder + "\" -r -y -bsp1", OutputCallback);

            return(exitCode == 0);

            /*
             *
             * // SharpCompress is waaaaaaaaaaaaaaaaaaaaaaaaaaaaaay to slow :|
             * try
             * {
             *  using (IArchive Archive = ArchiveFactory.Open(ArchivePath))
             *  {
             *      int BufferLength = 1 * 1024 * 1024;
             *      byte[] Buffer = new byte[BufferLength];
             *
             *      long TotalUncompressed = Archive.TotalUncompressSize;
             *      long Uncompressed = 0;
             *
             *      foreach (IArchiveEntry Entry in Archive.Entries.Where(entry => !entry.IsDirectory))
             *      {
             *          using (Stream ArchiveStream = Entry.OpenEntryStream())
             *          {
             *              using (FileStream FileStream = new FileStream(OutputFolder + @"\" + Entry.Key, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
             *              {
             *                  int BytesRead = 0;
             *                  while ((BytesRead = ArchiveStream.Read(Buffer, 0, Buffer.Length)) > 0)
             *                  {
             *                      FileStream.Write(Buffer, 0, BytesRead);
             *                      Uncompressed += BytesRead;
             *
             *                      float Progress = (float)Uncompressed / (float)TotalUncompressed;
             *                      ProgressCallback?.Invoke("Unpacking " + Entry.Key + "...", Progress);
             *                  }
             *              }
             *          }
             *      }
             *  }
             * }
             * catch (Exception Ex) // Should be more specific, but sharpcompress has so little documentation and looking through the code there are so many potential exceptions...
             * {
             *  Logger.Log(LogLevel.Error, LogCategory.Script, "Failed to extract archive with error: {0}", Ex.Message.ToString());
             *  return false;
             * }
             *
             * return true;
             */
        }