示例#1
0
    /// <summary>
    /// Loads the archive
    /// </summary>
    public void LoadArchive()
    {
        Logger.Info("The archive {0} is being loaded", DisplayName);

        // Clear existing items
        ClearAndDisposeItems();

        // Indicate that no files have pending edits
        ModifiedFilesCount = 0;
        HasModifiedFiles   = false;

        // Load the archive data
        ArchiveData = Manager.LoadArchive(ArchiveFileStream, Name);

        // Load the archive
        ArchiveData data = Manager.LoadArchiveData(ArchiveData, ArchiveFileStream, FilePath.Name);

        // Dispose the current generator
        ArchiveFileGenerator?.Dispose();

        // Save the generator
        ArchiveFileGenerator = data.Generator;

        // Add each directory
        foreach (ArchiveDirectory dir in data.Directories)
        {
            // Check if it's the root directory
            if (dir.DirectoryName == String.Empty)
            {
                // Add the files
                Files.AddRange(dir.Files.Select(x => new ArchiveFileViewModel(x, this)));

                continue;
            }

            // Keep track of the previous item
            ArchiveDirectoryViewModel prevItem = this;

            // Enumerate each sub directory
            foreach (string subDir in dir.DirectoryName.Trim(Manager.PathSeparatorCharacter).Split(Manager.PathSeparatorCharacter))
            {
                // Set the previous item and create the item if it doesn't already exist
                prevItem = prevItem.FirstOrDefault(x => x.ID == subDir) ?? prevItem.Add(subDir);
            }

            // Add the files
            prevItem.Files.AddRange(dir.Files.Select(x => new ArchiveFileViewModel(x, prevItem)));
        }
    }
示例#2
0
    /// <summary>
    /// Disposes the archive and its folders and files
    /// </summary>
    public override void Dispose()
    {
        // Cancel refreshing thumbnails
        ExplorerDialogViewModel.CancelInitializeFiles = true;

        // Dispose base class
        base.Dispose();

        // Dispose the stream
        ArchiveFileStream.Dispose();

        // Dispose every directory
        ClearAndDisposeItems();

        // Dispose the generator
        ArchiveFileGenerator?.Dispose();

        // Dispose the cache
        ThumbnailCache.Dispose();

        Logger.Info("The archive {0} has been disposed", DisplayName);
    }