/// <summary>
        /// Gets the RiotArhiveFile associated with the specified path.
        /// </summary>
        /// <param name="path">The path of the RiotArchiveFile to get.</param>
        /// <param name="file">When this method returns, if the key is found, contains the RiotArchiveFile associated with the specified key; otherwise, null.</param>
        /// <returns><c>true</c> if this RiotArchive contains an element with the specified key; otherwise, <c>false</c>.</returns>
        public bool TryGetValue(string path, out RiotArchiveFile file)
        {
            RiotArchiveFile outFile = null;
            var             result  = Archives.Any(a => a.TryGetValue(path, out outFile));

            file = outFile;
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="manager">The archive data manager</param>
        /// <param name="filePaths">The archive file paths</param>
        public ArchiveExplorerDialogViewModel(IArchiveExplorerDataManager manager, IEnumerable <FileSystemPath> filePaths)
        {
            try
            {
                // Set the default title
                Title = Resources.Archive_Title;

                // Get the manager
                Manager = manager;

                // Create the load action
                var load = new Operation(() => IsLoading = true, () => IsLoading = false, true);

                // Get the archives
                Archives = filePaths.Select(x => new ArchiveViewModel(x, manager, load, this)).ToArray();

                // Set the archive lock
                ArchiveLock = new AsyncLock();

                RL.Logger?.LogInformationSource($"The Archive Explorer is loading with {Archives.Length} archives");

                // Make sure we got an archive
                if (!Archives.Any())
                {
                    throw new ArgumentException("At least one archive path needs to be available");
                }

                // Lock when accessing the archive
                using (ArchiveLock.Lock())
                {
                    // Load each archive
                    foreach (var archive in Archives)
                    {
                        archive.LoadArchive();
                    }
                }

                // Select and expand the first item
                Archives.First().IsSelected = true;
                Archives.First().IsExpanded = true;
            }
            catch
            {
                // Make sure the view model gets disposed
                Dispose();

                throw;
            }
        }
Beispiel #3
0
    /// <summary>
    /// Default constructor
    /// </summary>
    /// <param name="manager">The archive data manager</param>
    /// <param name="filePaths">The archive file paths</param>
    public ArchiveExplorerDialogViewModel(IArchiveDataManager manager, FileSystemPath[] filePaths)
    {
        // Create commands
        NavigateToAddressCommand = new RelayCommand(() => LoadDirectory(CurrentDirectoryAddress));
        DeleteSelectedDirCommand = new AsyncRelayCommand(DeleteSelectedDirAsync);

        // Set properties
        CurrentDirectorySuggestions = new ObservableCollection <string>();
        StatusBarItems = new ObservableCollection <LocalizedString>();
        SearchProvider = new BaseSuggestionProvider(SearchForEntries);

        BindingOperations.EnableCollectionSynchronization(StatusBarItems, Application.Current);

        // TODO: Do not load the archives in the constructor! Create a separate init method or similar.

        try
        {
            // Set the default title
            Title = Resources.Archive_Title;

            // Get the manager
            Manager = manager;

            // Create the load action
            Operation load = new(() => IsLoading = true, () => IsLoading = false);

            // Get the archives
            Archives = filePaths.Select(x => new ArchiveViewModel(x, manager, load, this, filePaths.Any(f => f != x && f.Name == x.Name))).ToArray();

            // Set the archive lock
            ArchiveLock = new AsyncLock();

            Logger.Info("The Archive Explorer is loading with {0} archives", Archives.Length);

            // Make sure we got an archive
            if (!Archives.Any())
            {
                throw new ArgumentException("At least one archive path needs to be available");
            }

            // Lock when accessing the archive
            using (ArchiveLock.Lock())
            {
                // Load each archive
                foreach (var archive in Archives)
                {
                    archive.LoadArchive();
                }
            }

            // Select and expand the first item
            Archives.First().IsSelected = true;
            Archives.First().IsExpanded = true;
        }
        catch
        {
            // Make sure the view model gets disposed
            Dispose();

            throw;
        }
    }