Пример #1
0
        public void SendSuccess(string extraData1, string extraData2, bool ed2IsRtf)
        {
            UpdateHelperData updateHelperData = new UpdateHelperData(Response.Succeeded, UpdateStep.CheckForUpdate, extraData1, extraData2);

            updateHelperData.ExtraDataIsRTF[1] = ed2IsRtf;
            pipeServer.SendMessage(updateHelperData.GetByteArray());
        }
Пример #2
0
 public void StartPipeServer(Control OwnerHandle)
 {
     owner      = OwnerHandle;
     pipeServer = new PipeServer();
     pipeServer.MessageReceived    += pipeServer_MessageReceived;
     pipeServer.ClientDisconnected += pipeServer_ClientDisconnected;
     pipeServer.Start(UpdateHelperData.PipenameFromFilename(VersionTools.SelfLocation));
 }
Пример #3
0
        public void SendNewWyUpdate(string pipeName, int processID)
        {
            UpdateHelperData updateHelperData = new UpdateHelperData(UpdateAction.NewWyUpdateProcess);

            updateHelperData.ProcessID = processID;
            UpdateHelperData updateHelperData2 = updateHelperData;

            updateHelperData2.ExtraData.Add(pipeName);
            updateHelperData2.ExtraDataIsRTF.Add(item: false);
            pipeServer.SendMessage(updateHelperData2.GetByteArray());
        }
Пример #4
0
        void ServerReceivedData(byte[] message)
        {
            UpdateHelperData data = UpdateHelperData.FromByteArray(message);

            if (data.Action == UpdateAction.GetwyUpdateProcessID)
            {
                // send ProcessID
                pipeServer.SendMessage(new UpdateHelperData(UpdateAction.GetwyUpdateProcessID)
                {
                    ProcessID = Process.GetCurrentProcess().Id
                }.GetByteArray());
                return;
            }

            UpdateStep step = data.UpdateStep;

            if (step == UpdateStep.RestartInfo)
            {
                RestartInfoSent = true;

                // load the pre-install info
                if (data.ExtraData.Count > 0)
                {
                    FileOrServiceToExecuteAfterUpdate = data.ExtraData[0];
                    IsAService = data.ExtraDataIsRTF[0];
                }

                // load the AutoUpdateID (for writing to file whether the update failed or Succeeded)
                if (data.ExtraData.Count > 1)
                {
                    AutoUpdateID = data.ExtraData[1];
                }

                if (data.ExtraData.Count > 2)
                {
                    ExecutionArguments = data.ExtraData[2];
                }
            }
            else if (step == UpdateStep.Install)
            {
                // if we're already installing, don't bother to process the message again
                if (Installing)
                {
                    return;
                }

                Installing = true;
            }

            if (RequestReceived != null)
            {
                RequestReceived(this, data.Action, step);
            }
        }
Пример #5
0
        public void SendNewWyUpdate(string pipeName, int processID)
        {
            UpdateHelperData uh = new UpdateHelperData(UpdateAction.NewWyUpdateProcess)
            {
                ProcessID = processID
            };

            uh.ExtraData.Add(pipeName);
            uh.ExtraDataIsRTF.Add(false);

            pipeServer.SendMessage(uh.GetByteArray());
        }
Пример #6
0
        public static UpdateHelperData FromByteArray(byte[] data)
        {
            UpdateHelperData updateHelperData = new UpdateHelperData();

            using (MemoryStream memoryStream = new MemoryStream(data))
            {
                byte b = (byte)memoryStream.ReadByte();
                while (!ReadFiles.ReachedEndByte(memoryStream, b, byte.MaxValue))
                {
                    switch (b)
                    {
                    case 1:
                        updateHelperData.Action = (UpdateAction)ReadFiles.ReadInt(memoryStream);
                        break;

                    case 2:
                        updateHelperData.UpdateStep = (UpdateStep)ReadFiles.ReadInt(memoryStream);
                        break;

                    case 128:
                        updateHelperData.ExtraDataIsRTF.Add(item: true);
                        break;

                    case 3:
                        updateHelperData.ExtraData.Add(ReadFiles.ReadString(memoryStream));
                        if (updateHelperData.ExtraDataIsRTF.Count != updateHelperData.ExtraData.Count)
                        {
                            updateHelperData.ExtraDataIsRTF.Add(item: false);
                        }
                        break;

                    case 4:
                        updateHelperData.ProcessID = ReadFiles.ReadInt(memoryStream);
                        break;

                    case 5:
                        updateHelperData.Progress = ReadFiles.ReadInt(memoryStream);
                        break;

                    case 6:
                        updateHelperData.ResponseType = (Response)ReadFiles.ReadInt(memoryStream);
                        break;

                    default:
                        ReadFiles.SkipField(memoryStream, b);
                        break;
                    }
                    b = (byte)memoryStream.ReadByte();
                }
                return(updateHelperData);
            }
        }
Пример #7
0
        public void StartPipeServer(Control OwnerHandle)
        {
            //Note: this function can only be called once. Explosions otherwise.

            owner = OwnerHandle;

            pipeServer = new PipeServer();

            pipeServer.MessageReceived    += pipeServer_MessageReceived;
            pipeServer.ClientDisconnected += pipeServer_ClientDisconnected;

            pipeServer.Start(UpdateHelperData.PipenameFromFilename(VersionTools.SelfLocation));
        }
Пример #8
0
        private void ServerReceivedData(byte[] message)
        {
            UpdateHelperData updateHelperData = UpdateHelperData.FromByteArray(message);

            if (updateHelperData.Action == UpdateAction.GetwyUpdateProcessID)
            {
                pipeServer.SendMessage(new UpdateHelperData(UpdateAction.GetwyUpdateProcessID)
                {
                    ProcessID = Process.GetCurrentProcess().Id
                }.GetByteArray());
                return;
            }
            UpdateStep updateStep = updateHelperData.UpdateStep;

            switch (updateStep)
            {
            case UpdateStep.RestartInfo:
                RestartInfoSent = true;
                if (updateHelperData.ExtraData.Count > 0)
                {
                    FileOrServiceToExecuteAfterUpdate = updateHelperData.ExtraData[0];
                    IsAService = updateHelperData.ExtraDataIsRTF[0];
                }
                if (updateHelperData.ExtraData.Count > 1)
                {
                    AutoUpdateID = updateHelperData.ExtraData[1];
                }
                if (updateHelperData.ExtraData.Count > 2)
                {
                    ExecutionArguments = updateHelperData.ExtraData[2];
                }
                break;

            case UpdateStep.Install:
                if (Installing)
                {
                    return;
                }
                Installing = true;
                break;
            }
            if (this.RequestReceived != null)
            {
                this.RequestReceived(this, updateHelperData.Action, updateStep);
            }
        }
Пример #9
0
        public static UpdateHelperData FromByteArray(byte[] data)
        {
            UpdateHelperData uhData = new UpdateHelperData();

            using (MemoryStream ms = new MemoryStream(data))
            {
                byte bType = (byte)ms.ReadByte();

                //read until the end byte is detected
                while (!ReadFiles.ReachedEndByte(ms, bType, 0xFF))
                {
                    switch (bType)
                    {
                    case 0x01:
                        uhData.Action = (UpdateAction)ReadFiles.ReadInt(ms);
                        break;

                    case 0x02:     // update step we're on
                        uhData.UpdateStep = (UpdateStep)ReadFiles.ReadInt(ms);
                        break;

                    case 0x80:
                        uhData.ExtraDataIsRTF.Add(true);
                        break;

                    case 0x03:     // extra data

                        uhData.ExtraData.Add(ReadFiles.ReadString(ms));

                        // keep the 'ExtraDataIsRTF' same length as ExtraData
                        if (uhData.ExtraDataIsRTF.Count != uhData.ExtraData.Count)
                        {
                            uhData.ExtraDataIsRTF.Add(false);
                        }

                        break;

                    case 0x04:
                        uhData.ProcessID = ReadFiles.ReadInt(ms);
                        break;

                    case 0x05:
                        uhData.Progress = ReadFiles.ReadInt(ms);
                        break;

                    case 0x06:
                        uhData.ResponseType = (Response)ReadFiles.ReadInt(ms);
                        break;

                    // 0x07, 0x08, and 0x09 used to be links data - obsolete

                    default:
                        ReadFiles.SkipField(ms, bType);
                        break;
                    }

                    bType = (byte)ms.ReadByte();
                }
            }

            return(uhData);
        }
        void updateHelper_ProgressChanged(object sender, UpdateHelperData e)
        {
            switch (e.ResponseType)
            {
                case Response.Failed:

                    // show the error icon & menu
                    // and set last successful step
                    UpdateStepFailed(UpdateStepToUpdateStepOn(e.UpdateStep), new FailArgs { ErrorTitle = e.ExtraData[0], ErrorMessage = e.ExtraData[1] });

                    break;
                case Response.Succeeded:

                    switch (e.UpdateStep)
                    {
                        case UpdateStep.CheckForUpdate:

                            AutoUpdaterInfo.LastCheckedForUpdate = DateTime.Now;

                            // there's an update available
                            if (e.ExtraData.Count != 0)
                            {
                                version = e.ExtraData[0];

                                // if there are changes, save them
                                if (e.ExtraData.Count > 1)
                                {
                                    changes = e.ExtraData[1];
                                    changesAreRTF = e.ExtraDataIsRTF[1];
                                }

                                // save the changes to the AutoUpdateInfo file
                                AutoUpdaterInfo.UpdateVersion = version;
                                AutoUpdaterInfo.ChangesInLatestVersion = changes;
                                AutoUpdaterInfo.ChangesIsRTF = changesAreRTF;
                            }
                            else
                            {
                                // Clear saved version details for cases where we're
                                // continuing an update (the version details filled
                                // in from the AutoUpdaterInfo file) however,
                                // wyUpdate reports your app has since been updated.
                                // Thus we need to clear the saved info.
                                version = null;
                                changes = null;
                                changesAreRTF = false;

                                AutoUpdaterInfo.ClearSuccessError();
                            }

                            break;
                        case UpdateStep.DownloadUpdate:

                            UpdateStepOn = UpdateStepOn.UpdateDownloaded;

                            break;
                        case UpdateStep.RestartInfo:

                            // close this application so it can be updated
                            if (UseCloseAppNow)
                            {
                                // show client & send the "begin update" message
                                updateHelper.InstallNow();

                                // close this application so it can be updated
                                if (CloseAppNow != null)
                                    CloseAppNow(this, EventArgs.Empty);
                            }
                            else
                            {
                                // show client & send the "begin update" message
                                updateHelper.InstallNow();

                                // Use this since we are a console app (or Windows service)
                                Environment.Exit(0);
                            }
                            return;
                    }

                    StartNextStep(e.UpdateStep);

                    break;
                case Response.Progress:

                    // call the progress changed event
                    if (ProgressChanged != null)
                        ProgressChanged(this, e.Progress);

                    break;
            }
        }
 void updateHelper_PipeServerDisconnected(object sender, UpdateHelperData e)
 {
     // wyUpdate should only ever exit after success or failure
     // otherwise it is a premature exit (and needs to be treated as an error)
     if (UpdateStepOn == UpdateStepOn.Checking
         || UpdateStepOn == UpdateStepOn.DownloadingUpdate
         || UpdateStepOn == UpdateStepOn.ExtractingUpdate)
     {
         // wyUpdate premature exit error
         UpdateStepFailed(UpdateStepOn, new FailArgs { wyUpdatePrematureExit = true, ErrorTitle = e.ExtraData[0], ErrorMessage = e.ExtraData[1] });
     }
 }
Пример #12
0
        public static UpdateHelperData FromByteArray(byte[] data)
        {
            UpdateHelperData uhData = new UpdateHelperData();

            using (MemoryStream ms = new MemoryStream(data))
            {
                byte bType = (byte)ms.ReadByte();

                //read until the end byte is detected
                while (!ReadFiles.ReachedEndByte(ms, bType, 0xFF))
                {
                    switch (bType)
                    {
                        case 0x01:
                            uhData.Action = (UpdateAction)ReadFiles.ReadInt(ms);
                            break;
                        case 0x02: // update step we're on
                            uhData.UpdateStep = (UpdateStep)ReadFiles.ReadInt(ms);
                            break;
                        case 0x80:
                            uhData.ExtraDataIsRTF.Add(true);
                            break;
                        case 0x03: // extra data

                            uhData.ExtraData.Add(ReadFiles.ReadString(ms));

                            // keep the 'ExtraDataIsRTF' same length as ExtraData
                            if (uhData.ExtraDataIsRTF.Count != uhData.ExtraData.Count)
                                uhData.ExtraDataIsRTF.Add(false);

                            break;
                        case 0x04:
                            uhData.ProcessID = ReadFiles.ReadInt(ms);
                            break;
                        case 0x05:
                            uhData.Progress = ReadFiles.ReadInt(ms);
                            break;
                        case 0x06:
                            uhData.ResponseType = (Response)ReadFiles.ReadInt(ms);
                            break;

                        // 0x07, 0x08, and 0x09 used to be links data - obsolete

                        default:
                            ReadFiles.SkipField(ms, bType);
                            break;
                    }

                    bType = (byte)ms.ReadByte();
                }
            }

            return uhData;
        }
Пример #13
0
        void SendAsync(UpdateHelperData uhd)
        {
            // if currently working, add the new message to the stack
            if (bw != null)
            {
                sendBuffer.Push(uhd);
            }
            else
            {
                RecreateBackgroundWorker();

                // process immediately
                UpdateStep = uhd.UpdateStep == UpdateStep.ForceRecheckForUpdate ? UpdateStep.CheckForUpdate : uhd.UpdateStep;

                // begin sending to the client
                bw.RunWorkerAsync(uhd);
            }
        }
Пример #14
0
        void ProcessReceivedMessage(UpdateHelperData data)
        {
            if (data.Action == UpdateAction.GetwyUpdateProcessID)
            {
                ClientProcess = Process.GetProcessById(data.ProcessID);
                return;
            }

            if (data.Action == UpdateAction.NewWyUpdateProcess)
            {
                // disconnect from the existing pipeclient
                pipeClient.Disconnect();

                CreateNewPipeClient();

                try
                {
                    ClientProcess = Process.GetProcessById(data.ProcessID);
                }
                catch (Exception)
                {
                    // inform the AutomaticUpdater that wyUpdate is no longer running
                    if (PipeServerDisconnected != null)
                        PipeServerDisconnected(this, new UpdateHelperData(Response.Failed, UpdateStep, AUTranslation.C_PrematureExitTitle, "Failed to connect to the new version of wyUpdate.exe"));
                }

                TryToConnectToPipe(data.ExtraData[0]);

                // if the process is running - try to kill it
                if (!pipeClient.Connected)
                {
                    // inform the AutomaticUpdater that wyUpdate is no longer running
                    if (PipeServerDisconnected != null)
                        PipeServerDisconnected(this, new UpdateHelperData(Response.Failed, UpdateStep, AUTranslation.C_PrematureExitTitle, "Failed to connect to the new version of wyUpdate.exe"));
                }

                // begin where we left off
                // if update step == RestartInfo, we need to send the restart info as well
                if (ResendRestartInfo != null && UpdateStep == UpdateStep.RestartInfo)
                    ResendRestartInfo(this, EventArgs.Empty);
                else
                    SendAsync(new UpdateHelperData(UpdateStep));

                return;
            }

            if (data.UpdateStep != UpdateStep)
            {
                // this occurs when wyUpdate is on a separate step from the AutoUpdater

                UpdateStep prev = UpdateStep;

                // set new update step
                UpdateStep = data.UpdateStep;

                // tell AutoUpdater that the message we sent didn't respond in kind
                // e.g. we sent RestartInfo, and wyUpdate responded with DownloadUpdate
                // meaning we can't update yet, we're just begginning downloading the update
                if (UpdateStepMismatch != null)
                    UpdateStepMismatch(this, data.ResponseType, prev);
            }

            // wyUpdate will give us its main Window Handle so we can pass focus to it
            if (data.Action == UpdateAction.UpdateStep && data.UpdateStep == UpdateStep.RestartInfo)
                ClientWindowHandleToShow = data.ProcessID;

            if (data.ResponseType != Response.Nothing && ProgressChanged != null)
                ProgressChanged(this, data);
        }
Пример #15
0
        public void RestartInfo(string fileToExecute, string autoUpdateID, string argumentsForFiles, bool isAService)
        {
            UpdateHelperData uhd = new UpdateHelperData(UpdateStep.RestartInfo);

            uhd.ExtraData.Add(fileToExecute);
            uhd.ExtraDataIsRTF.Add(isAService);

            if (!string.IsNullOrEmpty(autoUpdateID))
            {
                uhd.ExtraData.Add(autoUpdateID);
                uhd.ExtraDataIsRTF.Add(false);

                if (!string.IsNullOrEmpty(argumentsForFiles))
                {
                    uhd.ExtraData.Add(argumentsForFiles);
                    uhd.ExtraDataIsRTF.Add(false);
                }
            }

            SendAsync(uhd);
        }
        void updateHelper_PipeServerDisconnected(object sender, UpdateHelperData e)
        {
            // wyUpdate should only ever exit after success or failure
            // otherwise it is a premature exit (and needs to be treated as an error)
            if (UpdateStepOn == UpdateStepOn.Checking
                || UpdateStepOn == UpdateStepOn.DownloadingUpdate
                || UpdateStepOn == UpdateStepOn.ExtractingUpdate
                || e.UpdateStep == UpdateStep.RestartInfo)
            {
                if (e.UpdateStep == UpdateStep.RestartInfo)
                {
                    if (ClosingAborted != null)
                        ClosingAborted(this, EventArgs.Empty);

                    ClosingForInstall = false;
                }

                // wyUpdate premature exit error
                UpdateStepFailed(UpdateStepOn, new FailArgs { wyUpdatePrematureExit = true, ErrorTitle = e.ExtraData[0], ErrorMessage = e.ExtraData[1] });
            }
        }
Пример #17
0
        public void SendSuccess(string extraData1, string extraData2, bool ed2IsRtf)
        {
            UpdateHelperData uh = new UpdateHelperData(Response.Succeeded, UpdateStep.CheckForUpdate, extraData1, extraData2);

            uh.ExtraDataIsRTF[1] = ed2IsRtf;

            pipeServer.SendMessage(uh.GetByteArray());
        }
Пример #18
0
        public void SendNewWyUpdate(string pipeName, int processID)
        {
            UpdateHelperData uh = new UpdateHelperData(UpdateAction.NewWyUpdateProcess) { ProcessID = processID };

            uh.ExtraData.Add(pipeName);
            uh.ExtraDataIsRTF.Add(false);

            pipeServer.SendMessage(uh.GetByteArray());
        }