示例#1
0
        internal void SaveFile(FileViewModelBase fileToSave, bool saveAsFlag = false)
        {
            if (fileToSave.FilePath == null || saveAsFlag)
            {
                var dlg = new SaveFileDialog();
                if (dlg.ShowDialog().GetValueOrDefault())
                {
                    fileToSave.FilePath = dlg.SafeFileName;
                }
            }

            if (fileToSave.FilePath == null)
            {
                return;
            }

            if (fileToSave is AudioFileViewModel)
            {
                // TODO : Save action
            }
            else if (fileToSave is GeneralFileViewModel)
            {
                GeneralFileViewModel file = fileToSave as GeneralFileViewModel;

                if (file.IsDirty)
                {
                    FileManager.WriteTextFile(file.FilePath, file.TextContent, Encoding.UTF8);
                }
            }
            else if (fileToSave is ImageFileViewModel)
            {
                // TODO : Save action
            }
            else if (fileToSave is JsonFileViewModel)
            {
                JsonFileViewModel file = fileToSave as JsonFileViewModel;

                if (file.IsDirty)
                {
                    FileManager.WriteTextFile(file.FilePath, file.DocumentText, Encoding.UTF8);
                }
            }
            else if (fileToSave is SaveFileViewModel)
            {
                // TODO : Save action
            }
            else if (fileToSave is ScriptFileViewModel)
            {
                // TODO : Save action
            }

            ActiveDocument.IsDirty = false;
            ActiveDocument.OnAfterSave(null);
        }
示例#2
0
        internal void CloseFile(FileViewModelBase fileToClose)
        {
            if (fileToClose.IsDirty)
            {
                var res = MessageBox.Show(string.Format("Save changes for file '{0}'?", fileToClose.FileName), "MView", MessageBoxButton.YesNoCancel);
                if (res == MessageBoxResult.Cancel)
                {
                    return;
                }

                if (res == MessageBoxResult.Yes)
                {
                    SaveFile(fileToClose);
                }
            }

            _files.Remove(fileToClose);
        }
示例#3
0
        private async void OnClickEncrypt()
        {
            // Check options.
            if (string.IsNullOrEmpty(_saveDirectory))
            {
                MessageBox.Show("Save directory path cannot be null or empty.", "MView", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (!Directory.Exists(_saveDirectory))
            {
                MessageBox.Show("Save directory does not exist.", "MView", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (string.IsNullOrEmpty(_encryptionKey) || !Regex.IsMatch(_encryptionKey, @"^[a-zA-Z0-9]{32,32}$"))
            {
                MessageBox.Show("Invalid encryption key is inputted.", "MView", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (IsBackupFiles)
            {
                if (string.IsNullOrEmpty(_backupDirectory))
                {
                    MessageBox.Show("Backup directory path cannot be null or empty.", "MView", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                if (!Directory.Exists(_backupDirectory))
                {
                    MessageBox.Show("Backup directory does not exist.", "MView", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }

            // Check files.
            if (ToolHostWithExplorerViewModel.Instance.IsUseCurrentFile)
            {
                if (Workspace.Instance.ActiveDocument != null)
                {
                    FileViewModelBase file = Workspace.Instance.ActiveDocument;

                    if (file.GetType() != typeof(AudioFileViewModel) && file.GetType() != typeof(ImageFileViewModel))
                    {
                        MessageBox.Show("You cannot encrypt the file that is currently open.", "MView", MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }
                }
            }

            if (ToolHostWithExplorerViewModel.Instance.SelectedItems.Count == 0)
            {
                MessageBox.Show("Select a file to proceed.", "MView", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            var task = Task.Run(() =>
            {
                // TODO : 백업 기능 추가, 확장자 변경 시키기.
                if (ToolHostWithExplorerViewModel.Instance.IsUseCurrentFile)
                {
                    Workspace.Instance.SetStatus(TaskStatusType.Working, "Encrypting resource...");

                    string filePath = Workspace.Instance.ActiveDocument.FilePath;
                    string savePath = Path.Combine(_saveDirectory, Path.GetFileName(filePath));
                    CryptographyProvider.EncryptHeader(filePath, savePath, _encryptionKey);

                    Workspace.Instance.SetStatus(TaskStatusType.Completed, "Completed.");
                }
                else
                {
                    Workspace.Instance.SetStatus(TaskStatusType.Loading, "Loading resources...");

                    // Get selected files.
                    string[] extensions = new string[] { ".ogg", ".m4a", ".wav", ".png" };
                    List <string> files = Workspace.Instance.FileExplorer.GetSelectedFiles(ToolHostWithExplorerViewModel.Instance.SelectedItems.ToList(), extensions.ToList());

                    // Make file dictionary.
                    string baseDirectory = ToolHostWithExplorerViewModel.Instance.Items[0].FullName;
                    Dictionary <string, string> fileDictionary     = Workspace.Instance.FileExplorer.IndexFromList(files, baseDirectory, _saveDirectory);
                    Dictionary <string, string> modifiedDictionary = new Dictionary <string, string>();

                    foreach (var pair in fileDictionary)
                    {
                        modifiedDictionary.Add(pair.Key, GetModifiedFilePath(pair.Value));
                    }


                    Workspace.Instance.SetStatus(TaskStatusType.Ready, "Resources are loaded successfully.");

                    Encrypt(fileDictionary, _encryptionKey);
                }
            });

            await task;
        }