void bw_DoWorkUnzip(object sender, DoWorkEventArgs e)
        {
            Exception except = null;

            try
            {
                try
                {
                    // remove update file (it's no longer needed)
                    File.Delete(Filename);
                }
                catch { }

                var zipFiles = Directory.EnumerateFiles(TempDirectory, "*.zip");
                ExtractUpdateFiles(zipFiles);

                // Delete zip files
                foreach (string zipFile in zipFiles)
                {
                    try
                    {
                        File.Delete(zipFile);
                    }
                    catch { }
                }

                // Setup update details
                UpdtDetails = new UpdateDetails();

                var folders = Directory.EnumerateDirectories(OutputDirectory);
                foreach (string folder in folders)
                {
                    var files = Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories);
                    foreach (string file in files)
                    {
                        UpdtDetails.UpdateFiles.Add(new UpdateFile()
                        {
                            Filename = file,
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                except = ex;
            }

            if (IsCancelled() || except != null)
            {
                // report cancellation
                bw.ReportProgress(0, new object[] { -1, -1, "Cancelling update...", ProgressStatus.None, null });

                // Delete temporary files

                if (except != null && except.GetType() != typeof(PatchApplicationException))
                {
                    // remove the entire temp directory
                    try
                    {
                        Directory.Delete(OutputDirectory, true);
                    }
                    catch { }
                }

                bw.ReportProgress(0, new object[] { -1, -1, string.Empty, ProgressStatus.Failure, except });
            }
            else
            {
                bw.ReportProgress(0, new object[] { -1, -1, string.Empty, ProgressStatus.Success, null });
            }
        }
Example #2
0
        public static UpdateDetails Load(string fileName)
        {
            UpdateDetails updtDetails = new UpdateDetails();

            try
            {
                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    // Read back the file identification data, if any
                    if (!ReadFiles.IsHeaderValid(fs, "IUUDFV2"))
                        throw new ArgumentException("Incorrect file identifier.");

                    UpdateFile tempUpdateFile = new UpdateFile();
                    int lastStartServiceArgOn = 0;

                    byte bType = (byte)fs.ReadByte();
                    while (!ReadFiles.ReachedEndByte(fs, bType, 0xFF))
                    {
                        switch (bType)
                        {
                            case 0x20://num reg changes
                                updtDetails.RegistryModifications = new List<RegChange>(ReadFiles.ReadInt(fs));
                                break;
                            case 0x21://num file infos
                                updtDetails.UpdateFiles = new List<UpdateFile>(ReadFiles.ReadInt(fs));
                                break;
                            case 0x8E:
                                updtDetails.RegistryModifications.Add(RegChange.ReadFromStream(fs));
                                break;
                            case 0x30:
                                updtDetails.PreviousCommonDesktopShortcuts.Add(ReadFiles.ReadDeprecatedString(fs));
                                break;
                            case 0x31:
                                updtDetails.PreviousCommonSMenuShortcuts.Add(ReadFiles.ReadDeprecatedString(fs));
                                break;
                            case 0x36:
                                updtDetails.PreviousCUserDesktopShortcuts.Add(ReadFiles.ReadString(fs));
                                break;
                            case 0x37:
                                updtDetails.PreviousCUserSMenuShortcuts.Add(ReadFiles.ReadString(fs));
                                break;
                            case 0x32: //service to stop
                                updtDetails.ServicesToStop.Add(ReadFiles.ReadString(fs));
                                break;
                            case 0x33: //service to start
                                updtDetails.ServicesToStart.Add(new StartService(ReadFiles.ReadString(fs)));
                                break;
                            case 0x34: // number of start arguments for the last service
                                updtDetails.ServicesToStart[updtDetails.ServicesToStart.Count - 1].Arguments =
                                    new string[ReadFiles.ReadInt(fs)];
                                lastStartServiceArgOn = 0;
                                break;
                            case 0x35:
                                updtDetails.ServicesToStart[updtDetails.ServicesToStart.Count - 1].Arguments[
                                    lastStartServiceArgOn] = ReadFiles.ReadString(fs);
                                lastStartServiceArgOn++;
                                break;
                            case 0x40:
                                tempUpdateFile.RelativePath = ReadFiles.ReadDeprecatedString(fs);
                                break;
                            case 0x41:
                                tempUpdateFile.Execute = ReadFiles.ReadBool(fs);
                                break;
                            case 0x42:
                                tempUpdateFile.ExBeforeUpdate = ReadFiles.ReadBool(fs);
                                break;
                            case 0x43:
                                tempUpdateFile.CommandLineArgs = ReadFiles.ReadDeprecatedString(fs);
                                break;
                            case 0x44:
                                tempUpdateFile.IsNETAssembly = ReadFiles.ReadBool(fs);
                                break;
                            case 0x45:
                                tempUpdateFile.WaitForExecution = ReadFiles.ReadBool(fs);
                                break;
                            case 0x8F:
                                tempUpdateFile.RollbackOnNonZeroRet = true;
                                break;
                            case 0x4D:
                                if (tempUpdateFile.RetExceptions == null)
                                    tempUpdateFile.RetExceptions = new List<int>();

                                tempUpdateFile.RetExceptions.Add(ReadFiles.ReadInt(fs));
                                break;
                            case 0x46:
                                tempUpdateFile.DeleteFile = ReadFiles.ReadBool(fs);
                                break;
                            case 0x47:
                                tempUpdateFile.DeltaPatchRelativePath = ReadFiles.ReadDeprecatedString(fs);
                                break;
                            case 0x48:
                                tempUpdateFile.NewFileAdler32 = ReadFiles.ReadLong(fs);
                                break;
                            case 0x49:
                                tempUpdateFile.CPUVersion = (CPUVersion)ReadFiles.ReadInt(fs);
                                break;
                            case 0x4A:
                                tempUpdateFile.ProcessWindowStyle = (System.Diagnostics.ProcessWindowStyle)ReadFiles.ReadInt(fs);
                                break;
                            case 0x4E:
                                tempUpdateFile.ElevationType = (ElevationType)ReadFiles.ReadInt(fs);
                                break;
                            case 0x4B:
                                tempUpdateFile.FrameworkVersion = (FrameworkVersion)ReadFiles.ReadInt(fs);
                                break;
                            case 0x4C:
                                tempUpdateFile.RegisterCOMDll = (COMRegistration)ReadFiles.ReadInt(fs);
                                break;
                            case 0x9B://end of file
                                updtDetails.UpdateFiles.Add(tempUpdateFile);
                                tempUpdateFile = new UpdateFile();
                                break;
                            case 0x8D:
                                updtDetails.ShortcutInfos.Add(ShortcutInfo.LoadFromStream(fs));
                                break;
                            case 0x60:
                                updtDetails.FoldersToDelete.Add(ReadFiles.ReadDeprecatedString(fs));
                                break;
                            default:
                                ReadFiles.SkipField(fs, bType);
                                break;
                        }

                        bType = (byte)fs.ReadByte();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("The update details file failed to open.\n\nFull details: " + ex.Message);
            }

            return updtDetails;
        }
Example #3
0
        public static UpdateDetails Load(string fileName)
        {
            UpdateDetails updtDetails = new UpdateDetails();

            try
            {
                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    // Read back the file identification data, if any
                    if (!ReadFiles.IsHeaderValid(fs, "IUUDFV2"))
                    {
                        throw new ArgumentException("Incorrect file identifier.");
                    }

                    UpdateFile tempUpdateFile        = new UpdateFile();
                    int        lastStartServiceArgOn = 0;

                    byte bType = (byte)fs.ReadByte();
                    while (!ReadFiles.ReachedEndByte(fs, bType, 0xFF))
                    {
                        switch (bType)
                        {
                        case 0x20:    //num reg changes
                            updtDetails.RegistryModifications = new List <RegChange>(ReadFiles.ReadInt(fs));
                            break;

                        case 0x21:    //num file infos
                            updtDetails.UpdateFiles = new List <UpdateFile>(ReadFiles.ReadInt(fs));
                            break;

                        case 0x8E:
                            updtDetails.RegistryModifications.Add(RegChange.ReadFromStream(fs));
                            break;

                        case 0x30:
                            updtDetails.PreviousCommonDesktopShortcuts.Add(ReadFiles.ReadDeprecatedString(fs));
                            break;

                        case 0x31:
                            updtDetails.PreviousCommonSMenuShortcuts.Add(ReadFiles.ReadDeprecatedString(fs));
                            break;

                        case 0x36:
                            updtDetails.PreviousCUserDesktopShortcuts.Add(ReadFiles.ReadString(fs));
                            break;

                        case 0x37:
                            updtDetails.PreviousCUserSMenuShortcuts.Add(ReadFiles.ReadString(fs));
                            break;

                        case 0x32:     //service to stop
                            updtDetails.ServicesToStop.Add(ReadFiles.ReadString(fs));
                            break;

                        case 0x33:     //service to start
                            updtDetails.ServicesToStart.Add(new StartService(ReadFiles.ReadString(fs)));
                            break;

                        case 0x34:     // number of start arguments for the last service
                            updtDetails.ServicesToStart[updtDetails.ServicesToStart.Count - 1].Arguments =
                                new string[ReadFiles.ReadInt(fs)];
                            lastStartServiceArgOn = 0;
                            break;

                        case 0x35:
                            updtDetails.ServicesToStart[updtDetails.ServicesToStart.Count - 1].Arguments[
                                lastStartServiceArgOn] = ReadFiles.ReadString(fs);
                            lastStartServiceArgOn++;
                            break;

                        case 0x40:
                            tempUpdateFile.RelativePath = ReadFiles.ReadDeprecatedString(fs);
                            break;

                        case 0x41:
                            tempUpdateFile.Execute = ReadFiles.ReadBool(fs);
                            break;

                        case 0x42:
                            tempUpdateFile.ExBeforeUpdate = ReadFiles.ReadBool(fs);
                            break;

                        case 0x43:
                            tempUpdateFile.CommandLineArgs = ReadFiles.ReadDeprecatedString(fs);
                            break;

                        case 0x44:
                            tempUpdateFile.IsNETAssembly = ReadFiles.ReadBool(fs);
                            break;

                        case 0x45:
                            tempUpdateFile.WaitForExecution = ReadFiles.ReadBool(fs);
                            break;

                        case 0x8F:
                            tempUpdateFile.RollbackOnNonZeroRet = true;
                            break;

                        case 0x4D:
                            if (tempUpdateFile.RetExceptions == null)
                            {
                                tempUpdateFile.RetExceptions = new List <int>();
                            }

                            tempUpdateFile.RetExceptions.Add(ReadFiles.ReadInt(fs));
                            break;

                        case 0x46:
                            tempUpdateFile.DeleteFile = ReadFiles.ReadBool(fs);
                            break;

                        case 0x47:
                            tempUpdateFile.DeltaPatchRelativePath = ReadFiles.ReadDeprecatedString(fs);
                            break;

                        case 0x48:
                            tempUpdateFile.NewFileAdler32 = ReadFiles.ReadLong(fs);
                            break;

                        case 0x49:
                            tempUpdateFile.CPUVersion = (CPUVersion)ReadFiles.ReadInt(fs);
                            break;

                        case 0x4A:
                            tempUpdateFile.ProcessWindowStyle = (System.Diagnostics.ProcessWindowStyle)ReadFiles.ReadInt(fs);
                            break;

                        case 0x4E:
                            tempUpdateFile.ElevationType = (ElevationType)ReadFiles.ReadInt(fs);
                            break;

                        case 0x4B:
                            tempUpdateFile.FrameworkVersion = (FrameworkVersion)ReadFiles.ReadInt(fs);
                            break;

                        case 0x4C:
                            tempUpdateFile.RegisterCOMDll = (COMRegistration)ReadFiles.ReadInt(fs);
                            break;

                        case 0x9B:    //end of file
                            updtDetails.UpdateFiles.Add(tempUpdateFile);
                            tempUpdateFile = new UpdateFile();
                            break;

                        case 0x8D:
                            updtDetails.ShortcutInfos.Add(ShortcutInfo.LoadFromStream(fs));
                            break;

                        case 0x60:
                            updtDetails.FoldersToDelete.Add(ReadFiles.ReadDeprecatedString(fs));
                            break;

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

                        bType = (byte)fs.ReadByte();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("The update details file failed to open.\n\nFull details: " + ex.Message);
            }

            return(updtDetails);
        }