private void Window_Loaded(object sender, RoutedEventArgs e) { if (Properties.Settings.Default["vfsfile"] == null || ((String)(Properties.Settings.Default["vfsfile"])).Length == 0) { var r = System.Windows.Forms.MessageBox.Show("首次启动 VFS 需要在磁盘上建立一个虚拟磁盘镜像文件,镜像文件大小为 1GB。\n点击确定后请选择一个可以写入的位置来建立此文件,点击取消关闭程序。", "磁盘镜像文件未找到", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Information); if (r == System.Windows.Forms.DialogResult.Cancel) { Close(); return; } using (var dialog = new System.Windows.Forms.SaveFileDialog()) { dialog.Title = "保存磁盘镜像文件"; dialog.FileName = "vfs.bin"; var result = dialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.Cancel) { Close(); return; } else { try { device = new FileAdapter(dialog.FileName, 1 << 10 << 10 << 10); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("打开镜像文件失败,可能您没有权限在该位置写入文件,或您内存不足。程序即将退出,请重新打开程序。"); Close(); return; } // 更新配置 Properties.Settings.Default["vfsfile"] = dialog.FileName; Properties.Settings.Default.Save(); } } } else { device = new FileAdapter((String)Properties.Settings.Default["vfsfile"], 1 << 10 << 10 << 10); } vfs = new VFS(device); if (!vfs.IsFormated()) { var result = System.Windows.Forms.MessageBox.Show("该磁盘镜像文件尚未格式化,是否格式化?", "VFS", System.Windows.Forms.MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.No) { Close(); return; } vfs.Format(device.Size() >> 10, 4); // 写入一个示例文件 var file = vfs.NewFile("/README.txt", VFS.FileMode.Create); file.Write(Encoding.UTF8.GetBytes("Hello world!\r\n\r\n这个文件是格式化时自动建立的,如果你看到了这个文件,说明一切工作正常。\r\n\r\n当你使用记事本修改这个文件并保存以后,它会同步到虚拟文件系统中。\r\n\r\n该虚拟文件系统是索引文件系统,inode 默认占总空间的 10%,理论可支持单一文件最大 2GB。")); System.Windows.Forms.MessageBox.Show("磁盘格式化成功!", "VFS", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } LoadDirectory("/"); UpdateInfo(); }
private void ButtonTool_Click(object sender, RoutedEventArgs e) { XamDialogWindow win = new XamDialogWindow() { Width = 350, Height = 150, StartupPosition = StartupPosition.Center, CloseButtonVisibility = Visibility.Collapsed }; win.Header = "格式化"; StackPanel stack = new StackPanel(); stack.VerticalAlignment = VerticalAlignment.Center; stack.Margin = new Thickness(10); Label label = new Label(); label.Content = "您确认要格式化文件系统吗?"; stack.Children.Add(label); StackPanel stackButton = new StackPanel(); stackButton.Orientation = Orientation.Horizontal; stackButton.HorizontalAlignment = HorizontalAlignment.Center; stack.Children.Add(stackButton); Button btnOK = new Button(); btnOK.Content = "格式化"; btnOK.Padding = new Thickness(10, 0, 10, 0); btnOK.Margin = new Thickness(10); stackButton.Children.Add(btnOK); Button btnCancel = new Button(); btnCancel.Content = "取消"; btnCancel.Padding = new Thickness(10, 0, 10, 0); btnCancel.Margin = new Thickness(10); stackButton.Children.Add(btnCancel); //FadeOutWindow(); win.Content = stack; win.IsModal = true; grid.Children.Add(win); btnOK.Click += delegate { VFS.Format(); currentDir = VFS.ROOT_DIR; recorder.Add(currentDir); listView.ItemsSource = VFS.ROOT_DIR.directoryData; url.Text = currentDir.GetPath(); win.Close(); grid.Children.Remove(win); }; btnCancel.Click += delegate { win.Close(); grid.Children.Remove(win); }; }