Exemple #1
0
        static FileModel()
        {
            Messenger.Default.Register(Application.Current, (NotificationMessage message) =>
            {
                if (message.NotificationType == NotificationType.Add)
                {
                    string parentPath = FileSystemHelper.GetParentFolderPath(message.Path);
                    if (FileModelCache.TryGetValue(parentPath, out FileModel parentFileModel))
                    {
                        string parsingName = FileSystemHelper.GetFileParsingName(message.Path);
                        if (String.IsNullOrEmpty(parsingName))
                        {
                            return;
                        }

                        FileModel fileModel = FromPath(parsingName);
                        if (fileModel.IsDirectory)
                        {
                            parentFileModel.Folders?.Add(fileModel);
                        }
                        else
                        {
                            parentFileModel.Files?.Add(fileModel);
                        }
                    }
                }
                else if (message.NotificationType == NotificationType.Remove)
                {
                    string parentPath = FileSystemHelper.GetParentFolderPath(message.Path);
                    if (FileModelCache.TryGetValue(parentPath, out FileModel parentFileModel) && FileModelCache.ContainsKey(message.Path))
                    {
                        FileModelCache.TryRemove(message.Path, out FileModel fileModel);
                        if (fileModel.IsDirectory)
                        {
                            parentFileModel.Folders?.Remove(fileModel);
                        }
                        else
                        {
                            parentFileModel.Files?.Remove(fileModel);
                        }
                    }
                }
                else if (message.NotificationType == NotificationType.Rename)
                {
                    if (FileModelCache.ContainsKey(message.Path))
                    {
                        FileModelCache.TryRemove(message.Path, out FileModel fileModel);

                        string parsingName = FileSystemHelper.GetFileParsingName(message.NewPath);
                        if (String.IsNullOrEmpty(parsingName))
                        {
                            return;
                        }

                        FileModelCache.TryAdd(parsingName, fileModel);
                        FromPath(parsingName);

                        if (fileModel.Folders != null)
                        {
                            foreach (FileModel folder in fileModel.Folders)
                            {
                                folder.ParentName = fileModel.Name;
                                folder.Rename(message.Path, message.NewPath);
                            }
                        }

                        if (fileModel.Files != null)
                        {
                            foreach (FileModel file in fileModel.Files)
                            {
                                file.ParentName = fileModel.Name;
                                file.Rename(message.Path, message.NewPath);
                            }
                        }
                    }
                }
                else if (message.NotificationType == NotificationType.Update)
                {
                    if (FileModelCache.ContainsKey(message.Path))
                    {
                        string parsingName = FileSystemHelper.GetFileParsingName(message.Path);
                        if (String.IsNullOrEmpty(parsingName))
                        {
                            return;
                        }

                        FromPath(parsingName);
                    }
                }
            });

            Settings.Default.SettingsSaving += (s, e) =>
            {
                if (Properties.Resources.Culture.Name != Settings.Default.Language)
                {
                    CultureResources.ChangeCulture(Settings.Default.Language);

                    FileSystemHelper.Computer.Name     = Properties.Resources.Computer;
                    FileSystemHelper.Computer.FullName = Properties.Resources.Computer;

                    FileSystemHelper.QuickAccess.Name     = Properties.Resources.QuickAccess;
                    FileSystemHelper.QuickAccess.FullName = Properties.Resources.QuickAccess;
                }
            };
        }