コード例 #1
0
ファイル: PackageUpdater.cs プロジェクト: vector-man/netide
        private void PerformUpdate(int index, RegistryKey packageKey)
        {
            var update = _pendingUpdates[index];

            OnProgressChanged(new ProgressEventArgs(
                                  String.Format(Labels.DownloadingPackage, update.PackageId),
                                  index,
                                  _pendingUpdates.Count
                                  ));

            string tempFileName = Path.GetTempFileName();

            try
            {
                DownloadPackage(packageKey, update.PackageId, tempFileName);

                OnProgressChanged(new ProgressEventArgs(
                                      packageKey.GetValue("Version") != null
                        ? String.Format(Labels.UpdatingPackage, update.PackageId)
                        : String.Format(Labels.InstallingPackage, update.PackageId),
                                      index,
                                      _pendingUpdates.Count
                                      ));

                new PackageInstaller(_env.Context, tempFileName).Execute();
            }
            finally
            {
                SEH.SinkExceptions(() => File.Delete(tempFileName));
            }
        }
コード例 #2
0
        private void DownloadComplete(string downloadFolder)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new Action(() => DownloadComplete(downloadFolder)));
                return;
            }

            // Get rid of the main form. We're starting the real update
            // process now and don't want the main form anymore.

            Dispose();

            try
            {
                string nguPath = Path.Combine(
                    Path.Combine(
                        downloadFolder,
                        Constants.ToolsFolder
                        ),
                    Constants.NuGetUpdateFileName
                    );

                NativeMethods.AllowSetForegroundWindow(NativeMethods.ASFW_ANY);

                using (var process = Process.Start(new ProcessStartInfo
                {
                    FileName = nguPath,
                    Arguments = String.Format(
                        "-i -p {0} -t {1} -s {2} -su {3} -sp {4} -- {5}",
                        Escaping.ShellEncode(Program.Arguments.Package),
                        Escaping.ShellEncode(Program.Arguments.Title),
                        Escaping.ShellEncode(Program.Arguments.Site),
                        Escaping.ShellEncode(Program.Arguments.SiteUserName),
                        Escaping.ShellEncode(Program.Arguments.SitePassword),
                        Escaping.ShellEncode(Program.ExtraArguments)
                        ),
                    UseShellExecute = false,
                    WorkingDirectory = downloadFolder
                }))
                {
                    process.WaitForExit();
                }

                SEH.SinkExceptions(() => Directory.Delete(downloadFolder, true));
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    this,
                    UILabels.StartSetupFailure + Environment.NewLine +
                    Environment.NewLine +
                    ex.Message,
                    Text,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
            }
        }
コード例 #3
0
        private void SignalWaitHandleCompletion(object state)
        {
            // We do not care whether this throws, because there really isn't a
            // fallback action to take.

            SEH.SinkExceptions(() => _synchronizationContext.Wait((IntPtr[])state, false, -1));

            SEH.SinkExceptions(() => BeginInvoke(new Action(Dispose)));
        }
コード例 #4
0
ファイル: NiPackageManager.cs プロジェクト: vector-man/netide
        private void RemovePendingUpdate()
        {
            // If we got here and we have a pending update, it means it has
            // been installed and we can safely delete it.

            var pendingUpdateLocation = GetPendingUpdateLocation();

            if (Directory.Exists(pendingUpdateLocation))
            {
                SEH.SinkExceptions(() => Directory.Delete(pendingUpdateLocation, true));
            }
        }
コード例 #5
0
ファイル: NiEnv.cs プロジェクト: vector-man/netide
        private void LoadContext(string path)
        {
            while (path != null)
            {
                string fileName = Path.Combine(path, Xml.Context.Context.FileName);

                if (File.Exists(fileName))
                {
                    SEH.SinkExceptions(() => LoadContextFromFile(fileName));

                    if (ContextName != null)
                    {
                        break;
                    }
                }

                path = Path.GetDirectoryName(path);
            }
        }
コード例 #6
0
ファイル: PackageUpdater.cs プロジェクト: vector-man/netide
        private void PerformRuntimeUpdate(int index, RegistryKey packageKey)
        {
            // A runtime update involves updating two packages. The core package
            // is of course updated, as part of the runtime update, we also
            // update the NetIde.Runtime package. This package contains the
            // main executable and is used to overwrite the bin directory
            // of the installation.

            OnProgressChanged(new ProgressEventArgs(
                                  String.Format(Labels.DownloadingPackage, RuntimePackageId),
                                  index,
                                  _pendingUpdates.Count
                                  ));

            string tempFileName = Path.GetTempFileName();

            try
            {
                DownloadPackage(packageKey, RuntimePackageId, tempFileName);

                new PackageRuntimeInstaller(_env.Context, tempFileName).Execute();
            }
            catch
            {
                // Cancel the core update to prevent from getting into an
                // endless loop.

                CancelCorePackageUpdate(_env);

                throw;
            }
            finally
            {
                SEH.SinkExceptions(() => File.Delete(tempFileName));
            }

            // The runtime installer restarted the application with a request
            // to update the runtime. We can exit.

            Environment.Exit(0);
        }
コード例 #7
0
            public override void InstallPackage(InstallPackage action)
            {
                string packageFolder = Runner.Environment.Config.PackageFolder;
                string toolsFolder   = Path.Combine(packageFolder, Constants.ToolsFolder);
                string targetPath    = Runner.Variables.GetRequired <string>(
                    Constants.ScriptVariables.TargetPath
                    );

                AddToInstallLog(new InstallLogCreateDirectory
                {
                    Path  = targetPath,
                    Force = false
                });

                if (!action.IntoRoot)
                {
                    targetPath = Path.Combine(targetPath, Constants.BinFolder);
                }

                string tempPath = null;

                try
                {
                    if (Runner.Mode == ScriptRunnerMode.Update)
                    {
                        tempPath = RemoveCurrentTargetPath(targetPath);
                    }

                    AddToInstallLog(new InstallLogCreateDirectory
                    {
                        Path  = targetPath,
                        Force = true
                    });

                    string startMenuPath = Runner.Variables.GetOptional <string>(
                        Constants.ScriptVariables.StartMenuPath
                        );

                    if (!String.IsNullOrEmpty(startMenuPath))
                    {
                        string startMenuBase = NativeMethods.SHGetFolderPath(
                            IntPtr.Zero,
                            NativeMethods.SpecialFolderCSIDL.CSIDL_STARTMENU,
                            IntPtr.Zero,
                            0
                            );

                        startMenuPath = Path.Combine(startMenuBase, startMenuPath);

                        AddToInstallLog(new InstallLogCreateDirectory
                        {
                            Path  = startMenuPath,
                            Force = false
                        });
                    }

                    int fileCount = Directory.GetFiles(toolsFolder, "*", SearchOption.AllDirectories).Length;

                    if (fileCount == 0)
                    {
                        return;
                    }

                    int currentFile = 0;

                    CopyDirectory(toolsFolder, targetPath, null, action.Overwrite, fileCount, ref currentFile);

                    CreateUninstallShortCut(targetPath);
                }
                finally
                {
                    if (tempPath != null)
                    {
                        SEH.SinkExceptions(() => Directory.Delete(tempPath, true));
                    }
                }
            }
コード例 #8
0
ファイル: NiPackageManager.cs プロジェクト: vector-man/netide
        private void ProcessRuntimeUpdate()
        {
            // A runtime update is requested by adding /RuntimeUpdate to
            // the arguments. The command line service knows this and always
            // checks for this argument.

            var commandLine = (INiCommandLine)GetService(typeof(INiCommandLine));

            bool   present;
            string value;

            ErrorUtil.ThrowOnFailure(commandLine.GetOption("/RuntimeUpdate", out present, out value));

            if (!present)
            {
                return;
            }

            var pendingUpdateLocation = GetPendingUpdateLocation();

            // And we want to copy into the bin folder.

            string target = Path.Combine(_env.FileSystemRoot, "bin");

            // Move the current target directory out of the way.

            string tempTarget;

            if (!TryMoveTarget(target, out tempTarget))
            {
                // If we aren't able to move the target out of the way
                // (i.e. can't take ownership of the directory), we can't
                // continue. We got here in the first place because of a
                // pending update to NetIde.Package.Core, so we cancel
                // this and just restart.

                PackageUpdater.CancelCorePackageUpdate(_env);
            }
            else
            {
                try
                {
                    CopyDirectory(pendingUpdateLocation, target);

                    // The restart will take care of removing the pending update
                    // location.
                }
                finally
                {
                    // And finally, remove the temporary target directory because
                    // this is of no use anymore.

                    if (tempTarget != null)
                    {
                        SEH.SinkExceptions(() => Directory.Delete(tempTarget, true));
                    }
                }
            }

            // We still need to update the NetIde.Package.Core package itself.

            // Restart the newly installed runtime.

            string fileName = Path.Combine(
                target,
                Path.GetFileName(GetType().Assembly.Location)
                );

            Process.Start(new ProcessStartInfo
            {
                FileName         = fileName,
                WorkingDirectory = _env.FileSystemRoot,
                UseShellExecute  = false
            });

            Environment.Exit(0);
        }