Ejemplo n.º 1
0
        public void Unpack(string filePath, string directoryPath)
        {
            InfoService.InitializeProgressMessageThread();
            if (String.IsNullOrEmpty(directoryPath))
            {
                directoryPath = Directory.GetCurrentDirectory();
            }
            Folder     folder     = null;
            FileStream fileStream = new FileStream(filePath, FileMode.Open);

            try
            {
                InfoService.ShowStatusMessage("Reading...");
                BinaryFormatter formatter = new BinaryFormatter();
                folder = (Folder)formatter.Deserialize(fileStream);
            }
            catch (SerializationException e)
            {
                InfoService.ShowErrorMessage("Failed to unpack. Reason: " + e.Message);
            }
            catch (FileNotFoundException e)
            {
                InfoService.ShowErrorMessage(e.Message);
            }
            finally
            {
                fileStream.Close();
            }
            InfoService.ShowStatusMessage("Unpacking...");
            CreateFoldersAndFilesFromInstance(folder, directoryPath);
            InfoService.ProcessFinished      = true;
            EstimatingService.ProcessedBytes = EstimatingService.NumberOfBytesToProcess;
            InfoService.ShowStatusMessage("Done.");
        }
Ejemplo n.º 2
0
        public void Save(string folderPath, string fileName)
        {
            InfoService.InitializeProgressMessageThread();
            folderPath = Path.GetFullPath(folderPath);
            string rootFolderName = folderPath.Split(Path.DirectorySeparatorChar).Last();

            if (String.IsNullOrEmpty(fileName))
            {
                fileName = rootFolderName;
            }
            Folder          folder;
            FileStream      fileStream = new FileStream(fileName + "." + ConfigurationManager.AppSettings["SavedFileFormat"], FileMode.Create);
            BinaryFormatter formatter  = new BinaryFormatter();

            try
            {
                InfoService.ShowStatusMessage("Reading...");
                folder = new Folder
                {
                    Name       = rootFolderName,
                    SubFolders = GetSubFolders(folderPath),
                    Files      = GetFiles(folderPath)
                };
                InfoService.ProcessFinished = true;
                InfoService.ShowStatusMessage("Saving...");
                formatter.Serialize(fileStream, folder);
            }
            catch (DirectoryNotFoundException e)
            {
                InfoService.ShowErrorMessage(e.Message);
            }
            catch (SerializationException e)
            {
                InfoService.ShowErrorMessage("Failed to save. Reason: " + e.Message);
            }
            finally
            {
                fileStream.Close();
                InfoService.ShowStatusMessage("Done.");
            }
        }