Beispiel #1
0
        private bool CopyVfsFileInternal(IArchiveFile vfsFile, string filename)
        {
            CopyProgressEventArgs args = new CopyProgressEventArgs
            {
                CurrentFileSize  = vfsFile.Size,
                CurrentFile      = vfsFile.Name,
                BytesCopied      = 0,
                TotalBytesCopied = 0
            };

            using (Stream inStream = vfsFile.OpenStream())
            {
                using (Stream outStream = FileSystem.Current.GetFile(filename).OpenStreamWithTimeout(FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    long   bytesRemaining = vfsFile.Size;
                    byte[] buffer         = new byte[BUFFER_SIZE];

                    while (bytesRemaining > 0)
                    {
                        int bytesRead = (int)(bytesRemaining < BUFFER_SIZE ? bytesRemaining : BUFFER_SIZE);

                        inStream.Read(buffer, 0, bytesRead);
                        outStream.Write(buffer, 0, bytesRead);
                        bytesRemaining -= bytesRead;

                        args.TotalBytesCopied += bytesRead;
                        args.BytesCopied      += bytesRead;
                        if (OnCopyProgress != null && (args.BytesCopied % PROGRESS_INCREMENT_SIZE == 0))
                        {
                            OnCopyProgress(this, args);
                            args.BytesCopied = 0;
                            if (args.Cancel)
                            {
                                Cancel();
                                return(true);
                            }
                        }
                    }
                }
            }

            if (OnCopyProgress != null)
            {
                OnCopyProgress(this, args);
            }

            return(false);
        }
Beispiel #2
0
 private void LoadImageFromArchive(IArchiveFile GameFile)
 {
     if (GameFile.Parent.Children.ContainsKey(Resources.GameIcon))
     {
         try
         {
             IArchiveFile file = GameFile.Parent.Children[Resources.GameIcon];
             using (var stream = file.OpenStream())
             {
                 _gameIconData = new byte[stream.Length];
                 stream.Read(_gameIconData, 0, (int)stream.Length);
             }
         }
         catch (Exception)
         {
             _gameIconData = null;
         }
     }
 }
Beispiel #3
0
 protected JsonEntity(IArchiveFile file)
 {
     try
     {
         using (var stream = file.OpenStream())
         {
             using (var reader = new StreamReader(stream))
             {
                 var json = JObject.Parse(reader.ReadToEnd());
                 DoLoad(json);
             }
         }
     }
     catch (Exception ex)
     {
         _errorCollection.Add("Unable to load data from " + file.Name + " - " + ex);
         Logger.Current.Write(ex, "Unable to load data from " + file.Name);
     }
 }
Beispiel #4
0
 protected JsonEntity(IArchiveFile file)
 {
     try
     {
         using (var stream = file.OpenStream())
         {
             using (var reader = new StreamReader(stream))
             {
                 var json = JObject.Parse(reader.ReadToEnd());
                 DoLoad(json);
             }
         }
     }
     catch (Exception ex)
     {
         _errorCollection.Add("Unable to load data from " + file.Name + " - " + ex);
         Logger.Current.Write(ex, "Unable to load data from " + file.Name);
     }
 }
        private bool CopyVfsFileInternal(IArchiveFile vfsFile, string filename)
        {
            CopyProgressEventArgs args = new CopyProgressEventArgs
                                             {
                                                 CurrentFileSize = vfsFile.Size,
                                                 CurrentFile = vfsFile.Name,
                                                 BytesCopied = 0,
                                                 TotalBytesCopied = 0
                                             };

            using (Stream inStream = vfsFile.OpenStream())
            {
                using (Stream outStream = FileSystem.Current.GetFile(filename).OpenStreamWithTimeout(FileMode.Create,FileAccess.Write,FileShare.None))
                {
                    long bytesRemaining = vfsFile.Size;
                    byte[] buffer = new byte[BUFFER_SIZE];

                    while (bytesRemaining > 0)
                    {
                        int bytesRead = (int)(bytesRemaining < BUFFER_SIZE ? bytesRemaining : BUFFER_SIZE);

                        inStream.Read(buffer, 0, bytesRead);
                        outStream.Write(buffer, 0, bytesRead);
                        bytesRemaining -= bytesRead;

                        args.TotalBytesCopied += bytesRead;
                        args.BytesCopied += bytesRead;
                        if (OnCopyProgress != null && (args.BytesCopied % PROGRESS_INCREMENT_SIZE == 0))
                        {
                            OnCopyProgress(this, args);
                            args.BytesCopied = 0;
                            if (args.Cancel)
                            {
                                Cancel();
                                return true;
                            }
                        }
                    }
                }
            }

            if (OnCopyProgress != null)
            {
                OnCopyProgress(this, args);
            }

            return false;
        }