예제 #1
1
파일: Updater.cs 프로젝트: herculesjr/razor
        private void ExtractFiles()
        {
            string tempPath = "Update.rar";
            if( File.Exists( tempPath ) )
            {
                UpdateStatus( "Extracting files..." );

                Unrar rar = new Unrar( tempPath );
                rar.DestinationPath = Directory.GetCurrentDirectory();
                rar.ExtractionProgress += new ExtractionProgressHandler( rar_ExtractionProgress );

                rar.Open();

                while( rar.ReadHeader() )
                {
                    if (rar.CurrentFile.FileName.ToLower() == "updater.exe" && File.Exists("Updater.exe"))
                    {
                        if (rar.CurrentFile.FileTime > File.GetLastWriteTime("Updater.exe"))
                        {
                            rar.CurrentFile.FileName = "New_Updater.exe";
                        }
                        else
                        {
                            rar.Skip();
                            continue;
                        }
                    }
                    else if (rar.CurrentFile.FileName.ToLower() == "unrar.dll" && File.Exists("unrar.dll"))
                    {
                        if (rar.CurrentFile.FileTime > File.GetLastWriteTime("unrar.dll"))
                        {
                            rar.CurrentFile.FileName = "New_unrar.dll";
                        }
                        else
                        {
                            rar.Skip();
                            continue;
                        }
                    }

                    while ( File.Exists( rar.CurrentFile.FileName ) )
                    {
                        try
                        {
                            File.Delete( rar.CurrentFile.FileName );
                        }
                        catch ( Exception e )
                        {
                            DialogResult res = MessageBox.Show( String.Format(
                                "Unable to delete file \"{0}\" (Error: {1})\nMake sure all instances of Razor are closed.\nRazor may be unusable until the update completes successfully.",
                                rar.CurrentFile.FileName, e.Message ),
                                "Access Denied",
                                MessageBoxButtons.AbortRetryIgnore,
                                MessageBoxIcon.Warning );

                            if ( res == DialogResult.Abort )
                            {
                                UpdateStatus( "Update ABORTED!" );
                                UpdateFailed();
                                return;
                            }
                            else if ( res == DialogResult.Ignore )
                            {
                                break; // just blindly try anyways
                            }
                            else
                            {
                                continue; // retry
                            }
                        }
                    }

                    rar.Extract();
                }

                rar.Close();
            }

            this.Invoke( new UpdateCompleteDelegate( UpdateComplete ) );
        }
예제 #2
1
        protected virtual void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                MessageBox.Show(this,
                    "An error occurred while downloading the update for RunUO: GDK\n" +
                    "Please try again later or post the following error on the bug board at " +
                    "http://www.runuoforge.org/gf/project/runuogdk/\n" + e.Error.Message,
                    "RunUO: GDK - Updater");
                return;
            }
            else
            {
                progressBar.Value = 100;

                string filePath = Path.Combine(Application.StartupPath, FILE_NAME);
                Unrar unrar = new Unrar(filePath);

                unrar.ExtractionProgress += new ExtractionProgressHandler(OnExtractionProgress);
                unrar.DestinationPath = Application.StartupPath;
                unrar.Open(Unrar.OpenMode.Extract);

                while (unrar.ReadHeader())
                {
                    if (unrar.CurrentFile.FileName == "Updater.exe")
                    {
                        unrar.CurrentFile.FileName = "Updater.exe.new";
                    }
                    else if (unrar.CurrentFile.FileName == "unrar.dll")
                    {
                        unrar.CurrentFile.FileName = "unrar.dll.new";
                    }

                    while (File.Exists(unrar.CurrentFile.FileName))
                    {
                        try
                        {
                            File.Delete(unrar.CurrentFile.FileName);
                            continue;
                        }
                        catch (Exception exception)
                        {
                            DialogResult result = MessageBox.Show(string.Format("Unable to delete file \"{0}\" (Error: {1})\nMake sure all instances of RunUO: GDK are closed.\nRunUO: GDK may be unusable until the update completes successfully.", unrar.CurrentFile.FileName, exception.Message), "RunUO: GDK - Updater", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);

                            if (result == DialogResult.Abort)
                            {
                                Application.Exit();
                                return;
                            }

                            if (result != DialogResult.Ignore)
                            {
                                continue;
                            }

                            break;
                        }
                    }

                    unrar.Extract(Path.Combine(Application.StartupPath, unrar.CurrentFile.FileName));
                }

                unrar.Close();
            }

            Process.Start(Path.Combine(Application.StartupPath, GDK_ASSEMBLY_NAME));
            Application.Exit();
        }
예제 #3
0
파일: Unrar.cs 프로젝트: uotools/runuogdk
 public void Dispose()
 {
     if (this.archiveHandle != IntPtr.Zero)
     {
         Unrar.RARCloseArchive(this.archiveHandle);
         this.archiveHandle = IntPtr.Zero;
     }
 }
예제 #4
0
파일: Unrar.cs 프로젝트: uotools/runuogdk
        private void Extract(string destinationPath, string destinationName)
        {
            int result = Unrar.RARProcessFile(this.archiveHandle, (int)Operation.Extract, destinationPath, destinationName);

            // Check result
            if (result != 0)
            {
                ProcessFileError(result);
            }
        }
예제 #5
0
파일: Unrar.cs 프로젝트: uotools/runuogdk
        /// <summary>
        /// Tests the ability to extract the current file without saving extracted data to disk
        /// </summary>
        /// <returns></returns>
        public void Test()
        {
            int result = Unrar.RARProcessFile(this.archiveHandle, (int)Operation.Test, string.Empty, string.Empty);

            // Check result
            if (result != 0)
            {
                ProcessFileError(result);
            }
        }
예제 #6
0
        private void Extract(string destinationPath, string destinationName)
        {
            int result = Unrar.RARProcessFile(this.archiveHandle, ( int )Operation.Extract, destinationPath, destinationName);

            // Check result
            if (result != 0)
            {
                try
                {
                    ProcessFileError(result);
                }
                catch (Exception e)
                {
                    Logger.Log(e.ToString());
                }
            }
        }
예제 #7
0
파일: Unrar.cs 프로젝트: uotools/runuogdk
        /// <summary>
        /// Close the currently open archive
        /// </summary>
        /// <returns></returns>
        public void Close()
        {
            // Exit without exception if no archive is open
            if (this.archiveHandle == IntPtr.Zero)
            {
                return;
            }

            // Close archive
            int result = Unrar.RARCloseArchive(this.archiveHandle);

            // Check result
            if (result != 0)
            {
                ProcessFileError(result);
            }
            else
            {
                this.archiveHandle = IntPtr.Zero;
            }
        }
예제 #8
0
        protected virtual void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                MessageBox.Show(this,
                                "An error occurred while downloading the update for RunUO: GDK\n" +
                                "Please try again later or post the following error on the bug board at " +
                                "http://www.runuoforge.org/gf/project/runuogdk/\n" + e.Error.Message,
                                "RunUO: GDK - Updater");
                return;
            }
            else
            {
                progressBar.Value = 100;

                string filePath = Path.Combine(Application.StartupPath, FILE_NAME);
                Unrar  unrar    = new Unrar(filePath);

                unrar.ExtractionProgress += new ExtractionProgressHandler(OnExtractionProgress);
                unrar.DestinationPath     = Application.StartupPath;
                unrar.Open(Unrar.OpenMode.Extract);

                while (unrar.ReadHeader())
                {
                    if (unrar.CurrentFile.FileName == "Updater.exe")
                    {
                        unrar.CurrentFile.FileName = "Updater.exe.new";
                    }
                    else if (unrar.CurrentFile.FileName == "unrar.dll")
                    {
                        unrar.CurrentFile.FileName = "unrar.dll.new";
                    }

                    while (File.Exists(unrar.CurrentFile.FileName))
                    {
                        try
                        {
                            File.Delete(unrar.CurrentFile.FileName);
                            continue;
                        }
                        catch (Exception exception)
                        {
                            DialogResult result = MessageBox.Show(string.Format("Unable to delete file \"{0}\" (Error: {1})\nMake sure all instances of RunUO: GDK are closed.\nRunUO: GDK may be unusable until the update completes successfully.", unrar.CurrentFile.FileName, exception.Message), "RunUO: GDK - Updater", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);

                            if (result == DialogResult.Abort)
                            {
                                Application.Exit();
                                return;
                            }

                            if (result != DialogResult.Ignore)
                            {
                                continue;
                            }

                            break;
                        }
                    }

                    unrar.Extract(Path.Combine(Application.StartupPath, unrar.CurrentFile.FileName));
                }

                unrar.Close();
            }

            Process.Start(Path.Combine(Application.StartupPath, GDK_ASSEMBLY_NAME));
            Application.Exit();
        }
예제 #9
0
        private void ExtractFiles()
        {
            string tempPath = "Update.rar";

            if (File.Exists(tempPath))
            {
                UpdateStatus("Extracting files...");

                Unrar rar = new Unrar(tempPath);
                rar.DestinationPath     = Directory.GetCurrentDirectory();
                rar.ExtractionProgress += new ExtractionProgressHandler(rar_ExtractionProgress);

                rar.Open();

                while (rar.ReadHeader())
                {
                    if (rar.CurrentFile.FileName.ToLower() == "updater.exe" && File.Exists("Updater.exe"))
                    {
                        if (rar.CurrentFile.FileTime > File.GetLastWriteTime("Updater.exe"))
                        {
                            rar.CurrentFile.FileName = "New_Updater.exe";
                        }
                        else
                        {
                            rar.Skip();
                            continue;
                        }
                    }
                    else if (rar.CurrentFile.FileName.ToLower() == "unrar.dll" && File.Exists("unrar.dll"))
                    {
                        if (rar.CurrentFile.FileTime > File.GetLastWriteTime("unrar.dll"))
                        {
                            rar.CurrentFile.FileName = "New_unrar.dll";
                        }
                        else
                        {
                            rar.Skip();
                            continue;
                        }
                    }

                    while (File.Exists(rar.CurrentFile.FileName))
                    {
                        try
                        {
                            File.Delete(rar.CurrentFile.FileName);
                        }
                        catch (Exception e)
                        {
                            DialogResult res = MessageBox.Show(String.Format(
                                                                   "Unable to delete file \"{0}\" (Error: {1})\nMake sure all instances of Razor are closed.\nRazor may be unusable until the update completes successfully.",
                                                                   rar.CurrentFile.FileName, e.Message),
                                                               "Access Denied",
                                                               MessageBoxButtons.AbortRetryIgnore,
                                                               MessageBoxIcon.Warning);

                            if (res == DialogResult.Abort)
                            {
                                UpdateStatus("Update ABORTED!");
                                UpdateFailed();
                                return;
                            }
                            else if (res == DialogResult.Ignore)
                            {
                                break;                                 // just blindly try anyways
                            }
                            else
                            {
                                continue;                                 // retry
                            }
                        }
                    }

                    rar.Extract();
                }

                rar.Close();
            }

            this.Invoke(new UpdateCompleteDelegate(UpdateComplete));
        }
예제 #10
0
파일: Unrar.cs 프로젝트: uotools/runuogdk
        /// <summary>
        /// Reads the next archive header and populates CurrentFile property data
        /// </summary>
        /// <returns></returns>
        public bool ReadHeader()
        {
            // Throw exception if archive not open
            if (this.archiveHandle == IntPtr.Zero)
            {
                throw new IOException("Archive is not open.");
            }

            // Initialize header struct
            this.header = new RARHeaderDataEx();
            header.Initialize();

            // Read next entry
            currentFile = null;
            int result = Unrar.RARReadHeaderEx(this.archiveHandle, ref this.header);

            // Check for error or end of archive
            if ((RarError)result == RarError.EndOfArchive)
            {
                return(false);
            }
            else if ((RarError)result == RarError.BadData)
            {
                throw new IOException("Archive data is corrupt.");
            }

            // Determine if new file
            if (((header.Flags & 0x01) != 0) && currentFile != null)
            {
                currentFile.ContinuedFromPrevious = true;
            }
            else
            {
                // New file, prepare header
                currentFile          = new RARFileInfo();
                currentFile.FileName = header.FileNameW.ToString();
                if ((header.Flags & 0x02) != 0)
                {
                    currentFile.ContinuedOnNext = true;
                }
                if (header.PackSizeHigh != 0)
                {
                    currentFile.PackedSize = (header.PackSizeHigh * 0x100000000) + header.PackSize;
                }
                else
                {
                    currentFile.PackedSize = header.PackSize;
                }
                if (header.UnpSizeHigh != 0)
                {
                    currentFile.UnpackedSize = (header.UnpSizeHigh * 0x100000000) + header.UnpSize;
                }
                else
                {
                    currentFile.UnpackedSize = header.UnpSize;
                }
                currentFile.HostOS          = (int)header.HostOS;
                currentFile.FileCRC         = header.FileCRC;
                currentFile.FileTime        = FromMSDOSTime(header.FileTime);
                currentFile.VersionToUnpack = (int)header.UnpVer;
                currentFile.Method          = (int)header.Method;
                currentFile.FileAttributes  = (int)header.FileAttr;
                currentFile.BytesExtracted  = 0;
                if ((header.Flags & 0xE0) == 0xE0)
                {
                    currentFile.IsDirectory = true;
                }
                this.OnNewFile();
            }

            // Return success
            return(true);
        }
예제 #11
0
파일: Unrar.cs 프로젝트: uotools/runuogdk
        /// <summary>
        /// Opens specified archive using the specified mode.
        /// </summary>
        /// <param name="archivePathName">Path of archive to open</param>
        /// <param name="openMode">Mode in which to open archive</param>
        public void Open(string archivePathName, OpenMode openMode)
        {
            IntPtr handle = IntPtr.Zero;

            // Close any previously open archives
            if (this.archiveHandle != IntPtr.Zero)
            {
                this.Close();
            }

            // Prepare extended open archive struct
            this.ArchivePathName = archivePathName;
            RAROpenArchiveDataEx openStruct = new RAROpenArchiveDataEx();

            openStruct.Initialize();
            openStruct.ArcName  = this.archivePathName + "\0";
            openStruct.ArcNameW = this.archivePathName + "\0";
            openStruct.OpenMode = (uint)openMode;
            if (this.retrieveComment)
            {
                openStruct.CmtBuf     = new string((char)0, 65536);
                openStruct.CmtBufSize = 65536;
            }
            else
            {
                openStruct.CmtBuf     = null;
                openStruct.CmtBufSize = 0;
            }

            // Open archive
            handle = Unrar.RAROpenArchiveEx(ref openStruct);

            // Check for success
            if (openStruct.OpenResult != 0)
            {
                switch ((RarError)openStruct.OpenResult)
                {
                case RarError.InsufficientMemory:
                    throw new OutOfMemoryException("Insufficient memory to perform operation.");

                case RarError.BadData:
                    throw new IOException("Archive header broken");

                case RarError.BadArchive:
                    throw new IOException("File is not a valid archive.");

                case RarError.OpenError:
                    throw new IOException("File could not be opened.");
                }
            }

            // Save handle and flags
            this.archiveHandle = handle;
            this.archiveFlags  = (ArchiveFlags)openStruct.Flags;

            // Set callback
            Unrar.RARSetCallback(this.archiveHandle, this.callback, this.GetHashCode());

            // If comment retrieved, save it
            if (openStruct.CmtState == 1)
            {
                this.comment = openStruct.CmtBuf.ToString();
            }

            // If password supplied, set it
            if (this.password.Length != 0)
            {
                Unrar.RARSetPassword(this.archiveHandle, this.password);
            }

            // Fire NewVolume event for first volume
            this.OnNewVolume(this.archivePathName);
        }