public void CreateFile() { var createFileWindow = new CreateUpdateFileWindow { Owner = Application.Current.MainWindow, File = new File() }; createFileWindow.ShowDialog(); if (createFileWindow.IsConfirmed) { var file = createFileWindow.File; file.InitializeCluster(); if (IsFileExists(file.Name)) { MessageBox.Show("File name already exist"); return; } //Add file in cluster ClusterTable.AddFileInCluster(file); Files.Add(file); } }
public void UpdateFile() { if (SelectedFile != null) { var oldName = SelectedFile.Name; var oldSize = SelectedFile.Size; var updateFileWindow = new CreateUpdateFileWindow { Owner = Application.Current.MainWindow, File = SelectedFile }; updateFileWindow.ShowDialog(); if (updateFileWindow.IsConfirmed) { var newFile = updateFileWindow.File; if (!newFile.Name.Equals(oldName) && IsFileExists(newFile.Name)) { MessageBox.Show("File name already exist"); return; } //Clear selection ClusterTable.SelectionClear(); if (newFile.Size > oldSize) { //New number cluster var numberNewCluster = (int)Math.Ceiling((decimal)newFile.Size / Settings.Settings.ClusterSize) - newFile.NumberClusterUse; newFile.IncreaseSizeFile(oldSize); ClusterTable.IncreaseClusterFile(numberNewCluster, newFile); } else if (newFile.Size < oldSize) //Smaller size { ClusterTable.DecreaseClusterFile(oldSize, newFile); newFile.DecreseSizeFile(oldSize); } //Reselect ClusterTable.SelectClusters(newFile.StartCluster.Address); } } }