Commit 3b7b11a9 authored by 潘栩锋's avatar 潘栩锋 🚴

优化 layout的多个备份,直接保存整个layout文件夹

parent 715ebee6
...@@ -32,82 +32,120 @@ namespace MultiLayout.MainEdit ...@@ -32,82 +32,120 @@ namespace MultiLayout.MainEdit
{ {
this.listview_profile.ItemsSource = mList; this.listview_profile.ItemsSource = mList;
//查找 layout/graphcustoms 下的全部文件 //查找 default/layout.default 下的全部文件夹
string dirPath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustoms"); string dirPath = System.IO.Path.Combine("default", "layout.default");
DirectoryInfo directoryInfo = new DirectoryInfo(dirPath); DirectoryInfo directoryInfo = new DirectoryInfo(dirPath);
if (!directoryInfo.Exists) { if (!directoryInfo.Exists) {
return; return;
} }
var files = directoryInfo.GetFiles("*.json"); var directoryInfos = directoryInfo.GetDirectories();
foreach (var file in files) {
mList.Add(System.IO.Path.GetFileNameWithoutExtension(file.Name)); foreach (var dirInfo in directoryInfos) {
//检查这个文件夹是否正确
string filePath = System.IO.Path.Combine(dirInfo.FullName, "graphcustom.json");
if (File.Exists(filePath)) {
//正确
mList.Add(dirInfo.Name);
}
} }
} }
private void button_read_Click(object sender, RoutedEventArgs e) private void button_read_Click(object sender, RoutedEventArgs e)
{ {
if (listview_profile.SelectedItem != null) if (listview_profile.SelectedItem == null)
{ return;
string strTipRebootForExecute = "需要重启,才能生效";
if (FLY.ControlLibrary.MyMessageBox.Show(strTipRebootForExecute) == true) string strTipRebootForExecute = "需要重启,才能生效";
{ if (FLY.ControlLibrary.MyMessageBox.Show(strTipRebootForExecute) != true)
string filename = listview_profile.SelectedItem as string;
string filePath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustoms", filename + ".json");
string destPath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustom.json");
File.Copy(filePath, destPath, true);
System.Windows.Forms.Application.Restart();
Application.Current.Shutdown();
}
return; return;
string dirname = listview_profile.SelectedItem as string;
string srcDirPath = System.IO.Path.Combine("default", "layout.default", dirname);
//把 srcDirPath 下的全部文件 复制到 FlyLayout.BasePath 下
DirectoryInfo srcDirInfo = new DirectoryInfo(srcDirPath);
var fileInfos = srcDirInfo.GetFiles();
foreach (var fileInfo in fileInfos)
{
string filePath = fileInfo.FullName;
string destPath = System.IO.Path.Combine(FlyLayout.BasePath, fileInfo.Name);
File.Copy(filePath, destPath, true);
} }
System.Windows.Forms.Application.Restart();
Application.Current.Shutdown();
} }
private void button_del_Click(object sender, RoutedEventArgs e) private void button_del_Click(object sender, RoutedEventArgs e)
{ {
if (listview_profile.SelectedItem != null) if (listview_profile.SelectedItem == null)
{ return;
string filename = listview_profile.SelectedItem as string;
string filePath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustoms", filename + ".json"); string dirname = listview_profile.SelectedItem as string;
File.Delete(filePath); if (FLY.ControlLibrary.MyMessageBox.Show($"将要删除 {dirname} ,是否确定?") != true)
return;
mList.Remove(filename);
FLY.ControlLibrary.Window_Tip.Show("删除成功", string srcDirPath = System.IO.Path.Combine("default", "layout.default", dirname);
filename, Directory.Delete(srcDirPath, true);
TimeSpan.FromSeconds(2));
} mList.Remove(dirname);
FLY.ControlLibrary.Window_Tip.Show("删除成功",
dirname,
TimeSpan.FromSeconds(2));
} }
private void button_save_Click(object sender, RoutedEventArgs e) private void button_save_Click(object sender, RoutedEventArgs e)
{ {
WdSaveFile w = new WdSaveFile(); WdSaveFile w = new WdSaveFile();
if (listview_profile.SelectedItem != null)
w.FileName = listview_profile.SelectedItem as string;
w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this); w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
if (w.ShowDialog() == true) { if (w.ShowDialog() != true)
if (mList.Contains(w.FileName)) { return;
if (FLY.ControlLibrary.MyMessageBox.Show("文件已经存在,是否覆盖?")!=true)
{
return;
}
}
string dirPath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustoms");
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
string filename = w.FileName;
string destPath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustoms", filename + ".json");
string srcPath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustom.json");
File.Copy(srcPath, destPath, true);
if (!mList.Contains(w.FileName))
{
mList.Add(filename);
}
FLY.ControlLibrary.Window_Tip.Show("保存成功",
filename,
TimeSpan.FromSeconds(2));
if (mList.Contains(w.FileName)) {
if (FLY.ControlLibrary.MyMessageBox.Show("布局文件已经存在,是否覆盖?")!=true)
return;
} }
string dirname = w.FileName;
string destDirPath = System.IO.Path.Combine("default", "layout.default", dirname);
string srcDirPath = FlyLayout.BasePath;
if (!Directory.Exists(destDirPath))
Directory.CreateDirectory(destDirPath);
//把 srcDirPath 下的全部文件 复制到 destDirPath 下
DirectoryInfo srcDirInfo = new DirectoryInfo(srcDirPath);
var fileInfos = srcDirInfo.GetFiles();
foreach (var fileInfo in fileInfos)
{
string filePath = fileInfo.FullName;
string destPath = System.IO.Path.Combine(destDirPath, fileInfo.Name);
File.Copy(filePath, destPath, true);
}
if (!mList.Contains(w.FileName))
mList.Add(w.FileName);
FLY.ControlLibrary.Window_Tip.Show("保存成功",
w.FileName,
TimeSpan.FromSeconds(2));
} }
} }
} }
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
<StackPanel Margin="5,20"> <StackPanel Margin="5,20">
<StackPanel Grid.Column="1" Margin="5"> <StackPanel Grid.Column="1" Margin="5">
<TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="请输入布局名称:" /> <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="请输入布局名称:" />
<StackPanel Orientation="Horizontal"> <Viewbox>
<TextBox Style="{StaticResource ResourceKey=TextBoxStyle_FieldContent}" Name="textbox_productname" Tag="Full" MinWidth="300"/> <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Name="textbox_productname" Tag="Full" MinWidth="300"/>
</StackPanel> </Viewbox>
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal"></StackPanel> <StackPanel Orientation="Horizontal"></StackPanel>
<Button Content="保存" Style="{StaticResource ButtonStyle2}" Margin="5" Width="auto" Click="button_save_Click" /> <Button Content="保存" Style="{StaticResource ButtonStyle2}" Margin="5" Width="auto" Click="button_save_Click" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment