예제 #1
0
        public static ServerFile Load(string fileName, string updatePathVar, string customUrlArgs)
        {
            ServerFile serv = new ServerFile();

            byte[] fileIDBytes = new byte[7];

            Stream fs = null;

            try
            {
                fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);

                // Read the first 7 bytes of identification data
                fs.Read(fileIDBytes, 0, 7);
            }
            catch (Exception)
            {
                if (fs != null)
                    fs.Close();

                throw;
            }

            // check for compression (see if PKZip header is there)
            if (fileIDBytes[0] == 0x50 && fileIDBytes[1] == 0x4B && fileIDBytes[2] == 0x03 && fileIDBytes[3] == 0x04)
            {
                // decompress the "actual" server file to memory
                fs.Close();

                using (ZipFile zip = ZipFile.Read(fileName))
                {
                    fs = new MemoryStream();

                    zip["0"].Extract(fs);
                }


                fs.Position = 0;

                // Read the first 7 bytes of identification data
                fs.Read(fileIDBytes, 0, 7);
            }


            // see if the file is in the correct server format

            string fileID = Encoding.UTF8.GetString(fileIDBytes);

            if (fileID != "IUSDFV2")
            {
                //free up the file so it can be deleted
                fs.Close();
                throw new Exception("The downloaded server file does not have the correct identifier. This is usually caused by file corruption.");
            }



            serv.VersionChoices.Add(new VersionChoice());

            byte bType = (byte)fs.ReadByte();
            while (!ReadFiles.ReachedEndByte(fs, bType, 0xFF))
            {
                switch (bType)
                {
                    case 0x01://Read New Version
                        serv.NewVersion = ReadFiles.ReadDeprecatedString(fs);
                        break;
                    case 0x07: //Min Client version
                        serv.MinClientVersion = ReadFiles.ReadDeprecatedString(fs);
                        break;
                    case 0x0B: //The version to update from
                        if (serv.VersionChoices.Count > 1 || serv.VersionChoices[0].Version != null)
                            serv.VersionChoices.Add(new VersionChoice());

                        serv.VersionChoices[serv.VersionChoices.Count - 1].Version = ReadFiles.ReadDeprecatedString(fs);
                        break;
                    case 0x03://Add update file site

                        string updateSite = ReadFiles.ReadDeprecatedString(fs);

                        if (updatePathVar != null)
                            updateSite = updateSite.Replace("%updatepath%", updatePathVar);

                        updateSite = updateSite.Replace("%urlargs%", customUrlArgs ?? string.Empty);

                        ClientFile.AddUniqueString(updateSite, serv.VersionChoices[serv.VersionChoices.Count - 1].FileSites);
                        
                        break;
                    case 0x80: //the changes text is in RTF format
                        serv.VersionChoices[serv.VersionChoices.Count - 1].RTFChanges = true;
                        break;
                    case 0x04://Read Changes
                        serv.VersionChoices[serv.VersionChoices.Count - 1].Changes = ReadFiles.ReadDeprecatedString(fs);
                        break;
                    case 0x09://update's filesize
                        serv.VersionChoices[serv.VersionChoices.Count - 1].FileSize = ReadFiles.ReadLong(fs);
                        break;
                    case 0x08://update's Adler32 checksum
                        serv.VersionChoices[serv.VersionChoices.Count - 1].Adler32 = ReadFiles.ReadLong(fs);
                        break;
                    case 0x14: // signed SHA1 hash
                        serv.VersionChoices[serv.VersionChoices.Count - 1].SignedSHA1Hash = ReadFiles.ReadByteArray(fs);
                        break;
                    case 0x0A: //Installing to which directories?
                        serv.VersionChoices[serv.VersionChoices.Count - 1].InstallingTo = (InstallingTo)ReadFiles.ReadInt(fs);
                        break;
                    case 0x8E: //the RegChanges (built with wyBuid 2.6.11.4 and below)
                        if (RegChange.ReadFromStream(fs).RegBasekey != RegBasekeys.HKEY_CURRENT_USER)
                            serv.VersionChoices[serv.VersionChoices.Count - 1].InstallingTo |= InstallingTo.NonCurrentUserReg;
                        break;
                    case 0x20:
                        serv.NoUpdateToLatestLinkText = ReadFiles.ReadDeprecatedString(fs);
                        break;
                    case 0x21:
                        serv.NoUpdateToLatestLinkURL = ReadFiles.ReadDeprecatedString(fs);
                        break;
                    case 0x0F:
                        //skip over the integer (4 bytes) length
                        //this is just used to trick pre-1.0 Final versions
                        //of wyUpdate to correctly read the server file correctly
                        fs.Position += 4;
                        break;
                    default:
                        ReadFiles.SkipField(fs, bType);
                        break;
                }

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

            fs.Close();

            return serv;
        }
예제 #2
0
        public static ServerFile Load(string fileName, string updatePathVar, string customUrlArgs)
        {
            ServerFile serv = new ServerFile();

            byte[] fileIDBytes = new byte[7];

            Stream fs = null;

            try
            {
                fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);

                // Read the first 7 bytes of identification data
                fs.Read(fileIDBytes, 0, 7);
            }
            catch (Exception)
            {
                if (fs != null)
                {
                    fs.Close();
                }

                throw;
            }

            // check for compression (see if PKZip header is there)
            if (fileIDBytes[0] == 0x50 && fileIDBytes[1] == 0x4B && fileIDBytes[2] == 0x03 && fileIDBytes[3] == 0x04)
            {
                // decompress the "actual" server file to memory
                fs.Close();

                using (ZipFile zip = ZipFile.Read(fileName))
                {
                    fs = new MemoryStream();

                    zip["0"].Extract(fs);
                }


                fs.Position = 0;

                // Read the first 7 bytes of identification data
                fs.Read(fileIDBytes, 0, 7);
            }


            // see if the file is in the correct server format

            string fileID = Encoding.UTF8.GetString(fileIDBytes);

            if (fileID != "IUSDFV2")
            {
                //free up the file so it can be deleted
                fs.Close();
                throw new Exception("The downloaded server file does not have the correct identifier. This is usually caused by file corruption.");
            }



            serv.VersionChoices.Add(new VersionChoice());

            byte bType = (byte)fs.ReadByte();

            while (!ReadFiles.ReachedEndByte(fs, bType, 0xFF))
            {
                switch (bType)
                {
                case 0x01:    //Read New Version
                    serv.NewVersion = ReadFiles.ReadDeprecatedString(fs);
                    break;

                case 0x07:     //Min Client version
                    serv.MinClientVersion = ReadFiles.ReadDeprecatedString(fs);
                    break;

                case 0x0B:     //The version to update from
                    if (serv.VersionChoices.Count > 1 || serv.VersionChoices[0].Version != null)
                    {
                        serv.VersionChoices.Add(new VersionChoice());
                    }

                    serv.VersionChoices[serv.VersionChoices.Count - 1].Version = ReadFiles.ReadDeprecatedString(fs);
                    break;

                case 0x03:    //Add update file site

                    string updateSite = ReadFiles.ReadDeprecatedString(fs);

                    if (updatePathVar != null)
                    {
                        updateSite = updateSite.Replace("%updatepath%", updatePathVar);
                    }

                    updateSite = updateSite.Replace("%urlargs%", customUrlArgs ?? string.Empty);

                    ClientFile.AddUniqueString(updateSite, serv.VersionChoices[serv.VersionChoices.Count - 1].FileSites);

                    break;

                case 0x80:     //the changes text is in RTF format
                    serv.VersionChoices[serv.VersionChoices.Count - 1].RTFChanges = true;
                    break;

                case 0x04:    //Read Changes
                    serv.VersionChoices[serv.VersionChoices.Count - 1].Changes = ReadFiles.ReadDeprecatedString(fs);
                    break;

                case 0x09:    //update's filesize
                    serv.VersionChoices[serv.VersionChoices.Count - 1].FileSize = ReadFiles.ReadLong(fs);
                    break;

                case 0x08:    //update's Adler32 checksum
                    serv.VersionChoices[serv.VersionChoices.Count - 1].Adler32 = ReadFiles.ReadLong(fs);
                    break;

                case 0x14:     // signed SHA1 hash
                    serv.VersionChoices[serv.VersionChoices.Count - 1].SignedSHA1Hash = ReadFiles.ReadByteArray(fs);
                    break;

                case 0x0A:     //Installing to which directories?
                    serv.VersionChoices[serv.VersionChoices.Count - 1].InstallingTo = (InstallingTo)ReadFiles.ReadInt(fs);
                    break;

                case 0x8E:     //the RegChanges (built with wyBuid 2.6.11.4 and below)
                    if (RegChange.ReadFromStream(fs).RegBasekey != RegBasekeys.HKEY_CURRENT_USER)
                    {
                        serv.VersionChoices[serv.VersionChoices.Count - 1].InstallingTo |= InstallingTo.NonCurrentUserReg;
                    }
                    break;

                case 0x20:
                    serv.NoUpdateToLatestLinkText = ReadFiles.ReadDeprecatedString(fs);
                    break;

                case 0x21:
                    serv.NoUpdateToLatestLinkURL = ReadFiles.ReadDeprecatedString(fs);
                    break;

                case 0x0F:
                    //skip over the integer (4 bytes) length
                    //this is just used to trick pre-1.0 Final versions
                    //of wyUpdate to correctly read the server file correctly
                    fs.Position += 4;
                    break;

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

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

            fs.Close();

            return(serv);
        }
예제 #3
0
        public frmMain(string[] args)
        {
            //sets to SegoeUI on Vista
            Font = SystemFonts.MessageBoxFont;

            // check if user is an admin for windows 2000+
            IsAdmin = VistaTools.IsUserAnAdmin();

            InitializeComponent();

            //enable Lazy SSL for all downloads
            FileDownloader.EnableLazySSL();

            //resize the client so its client region = 500x360
            if (ClientRectangle.Width != 500)
                Width = (Width - ClientRectangle.Width) + 500;

            if (ClientRectangle.Height != 360)
                Height = (Height - ClientRectangle.Height) + 360;

            //add the panelDisplaying to form
            panelDisplaying.TabIndex = 0;
            Controls.Add(panelDisplaying);

            try
            {
                //process commandline argument
                Arguments commands = new Arguments(args);
                ProcessArguments(commands);

                // load the self update information
                if (!string.IsNullOrEmpty(selfUpdateFileLoc))
                {
                    //Note: always load the selfupdate data before the automatic update data
                    LoadSelfUpdateData(selfUpdateFileLoc);
                    ConfigureProxySettings();

                    //TODO: wyUp 3.0: excise this hack
                    //if the loaded file is from RC1, then update self and bail out
                    if (selfUpdateFromRC1)
                    {
                        //install the new client, and relaunch it to continue the update
                        if (needElevation && NeedElevationToUpdate())
                        {
                            //the user "elevated" as a non-admin user
                            //warn the user of their idiocy
                            error = clientLang.AdminError;

                            //set to false so new client won't be launched in frmMain_Load()
                            selfUpdateFromRC1 = false;

                            ShowFrame(Frame.Error);
                        }
                        else
                        {
                            needElevation = false;

                            FileAttributes atr = File.GetAttributes(oldSelfLocation);
                            bool resetAttributes = (atr & FileAttributes.Hidden) != 0 || (atr & FileAttributes.ReadOnly) != 0 || (atr & FileAttributes.System) != 0;

                            // remove the ReadOnly & Hidden atributes temporarily
                            if (resetAttributes)
                                File.SetAttributes(oldSelfLocation, FileAttributes.Normal);

                            //Install the new client
                            File.Copy(newSelfLocation, oldSelfLocation, true);

                            if (resetAttributes)
                                File.SetAttributes(oldSelfLocation, atr);

                            //Relaunch self in OnLoad()
                        }

                        //bail out
                        return;
                    }
                }
                else // not self-updating
                {
                    ConfigureProxySettings();
                }

                //Load the client information
                if (clientFileType == ClientFileType.PreRC2)
                    //TODO: wyUp 3.0: stop supporting old client files (barely anyone uses RC2).
                    update.OpenObsoleteClientFile(clientFileLoc);
                else
                    update.OpenClientFile(clientFileLoc, clientLang, forcedLanguageCulture, updatePathVar, customUrlArgs);

                clientLang.SetVariables(update.ProductName, update.InstalledVersion);
            }
            catch (Exception ex)
            {
                clientLang.SetVariables(update.ProductName, update.InstalledVersion);

                error = "Client file failed to load. The client.wyc file might be corrupt.";
                errorDetails = ex.Message;

                ShowFrame(Frame.Error);
                return;
            }

            //sets up Next & Cancel buttons
            SetButtonText();

            //set header alignment, etc.
            panelDisplaying.HeaderImageAlign = update.HeaderImageAlign;

            if (update.HeaderTextIndent >= 0)
                panelDisplaying.HeaderIndent = update.HeaderTextIndent;

            panelDisplaying.HideHeaderDivider = update.HideHeaderDivider;

            // set the 
            if (update.CustomWyUpdateTitle != null)
                Text = update.CustomWyUpdateTitle;

            try
            {
                if (!string.IsNullOrEmpty(update.HeaderTextColorName))
                    panelDisplaying.HeaderTextColor = Color.FromName(update.HeaderTextColorName);
            }
            catch { }

            //load the Side/Top images
            panelDisplaying.TopImage = update.TopImage;
            panelDisplaying.SideImage = update.SideImage;

            if (isAutoUpdateMode)
            {
                try
                {
                    // create the temp folder where we'll store the updates long term
                    if (tempDirectory == null)
                        tempDirectory = CreateAutoUpdateTempFolder();
                }
                catch (Exception ex)
                {
                    error = clientLang.GeneralUpdateError;
                    errorDetails = "Failed to create the automatic updater temp folder: " + ex.Message;

                    ShowFrame(Frame.Error);
                    return;
                }
                
                try
                {
                    // load the previous auto update state from "autoupdate"
                    LoadAutoUpdateData();
                    ConfigureProxySettings();
                }
                catch
                {
                    startStep = UpdateStepOn.Checking;
                }
            }
            else if (SelfUpdateState == SelfUpdateState.FullUpdate)
            {
                try
                {
                    // load the server file for MinClient needed details (i.e. failure case)
                    ServerFile = ServerFile.Load(serverFileLoc, updatePathVar, customUrlArgs);

                    //load the self-update server file
                    LoadClientServerFile();
                    clientLang.NewVersion = SelfServerFile.NewVersion;
                }
                catch (Exception ex)
                {
                    error = clientLang.ServerError;
                    errorDetails = ex.Message;

                    ShowFrame(Frame.Error);
                    return;
                }

                if (needElevation && NeedElevationToUpdate())
                {
                    //the user "elevated" as a non-admin user
                    //warn the user of their idiocy
                    error = clientLang.AdminError;
                    ShowFrame(Frame.Error);
                }
                else
                {
                    needElevation = false;

                    //begin updating the product
                    ShowFrame(Frame.InstallUpdates);
                }
            }
            //continuing from elevation or self update (or both)
            else if (SelfUpdateState == SelfUpdateState.ContinuingRegularUpdate)
            {
                try
                {
                    //load the server file (without filling the 'changes' box & without downloading the wyUpdate Server file)
                    LoadServerFile(false);
                }
                catch (Exception ex)
                {
                    error = clientLang.ServerError;
                    errorDetails = ex.Message;

                    ShowFrame(Frame.Error);
                    return;
                }

                if (needElevation && NeedElevationToUpdate())
                {
                    // the user "elevated" as a non-admin user
                    // warn the user of their idiocy
                    error = clientLang.AdminError;

                    ShowFrame(Frame.Error);
                }
                else
                {
                    needElevation = false;

                    //begin updating the product
                    ShowFrame(Frame.InstallUpdates);
                }
            }
            else if (!uninstalling)
                startStep = UpdateStepOn.Checking;
        }