-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathFileExplorer.xaml.cs
116 lines (108 loc) · 4.5 KB
/
FileExplorer.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace NodeMCU_Studio_2015
{
/// <summary>
/// Interaction logic for FileExplorer.xaml
/// </summary>
public partial class FileExplorer : Window
{
public FileExplorer() {
InitializeComponent();
}
private void load_button_Click( Object sender , RoutedEventArgs e ) {
var last_value = this.load_button.IsEnabled;
Task.Factory.StartNew( () => {
this.listBox.Dispatcher.Invoke( new Action( () => {
this.load_button.IsEnabled = !last_value;
} ) );
var path = Workspace.Instance.LuaDeivceProgramsDirectory;
if ( Directory.Exists( path ) ) {
Directory.Delete( path , true );
while ( Directory.Exists( path ) ) ;
}
Directory.CreateDirectory( path );
while ( !Directory.Exists( path ) ) ;
var list = Workspace.Instance.Load();
this.listBox.Dispatcher.Invoke( new Action( () => {
this.listBox.Items.Clear();
foreach ( var f in list ) {
this.listBox.Items.Add( f );
}
this.load_button.IsEnabled = last_value;
} ) );
} );
}
private void listBox_SelectionChanged( Object sender , SelectionChangedEventArgs e ) {
var f = this.listBox.SelectedItem as string;
var path = Workspace.Instance.LuaDeivceProgramsDirectory;
if ( string.IsNullOrWhiteSpace( f ) ) {
this.delete_button.IsEnabled = false;
} else {
if ( !File.Exists( path + f ) ) {
var context = Workspace.Instance.Load( f );
FileStream file = new FileStream( path + f , FileMode.Create );
StreamWriter writer = new StreamWriter( file );
writer.Write( context );
writer.Flush();
file.Close();
}
this.delete_button.IsEnabled = true;
}
}
private void delete_button_Click( Object sender , RoutedEventArgs e ) {
var last_value = this.delete_button.IsEnabled;
this.listBox.Dispatcher.Invoke( new Action( () => {
this.delete_button.IsEnabled = !last_value;
} ) );
var file = this.listBox.SelectedItem as string;
if ( !string.IsNullOrWhiteSpace( file ) ) {
Workspace.Instance.Delete( file );
this.listBox.Items.Remove( file );
}
this.delete_button.IsEnabled = last_value;
}
private void ok_button_Click( Object sender , RoutedEventArgs e ) {
this.DialogResult = true;
}
private void CopyAll_Click( Object sender , RoutedEventArgs e ) {
Task.Factory.StartNew( () => {
this.listBox.Dispatcher.Invoke( new Action( () => {
this.CopyAll.IsEnabled = false;
} ) );
var list = this.listBox.Items.Cast<string>();
var path = Workspace.Instance.LuaDeivceProgramsDirectory;
foreach ( var f in list ) {
if ( !File.Exists( path + f ) ) {
var context = Workspace.Instance.Load( f );
FileStream file = new FileStream( path + f , FileMode.Create );
StreamWriter writer = new StreamWriter( file );
writer.Write( context );
writer.Flush();
file.Close();
}
if ( !File.Exists( Workspace.Instance.LuaProgramsDirectory + f ) ) {
File.Copy( path + f , Workspace.Instance.LuaProgramsDirectory + f , false );
}
}
this.listBox.Dispatcher.Invoke( new Action( () => {
this.CopyAll.IsEnabled = true;
Workspace.Instance.RefreshWorkspace();
} ) );
} );
}
}
}