-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
97 lines (84 loc) · 2.7 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
97 lines (84 loc) · 2.7 KB
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
using System.Windows;
using Microsoft.Win32;
using Ookii.Dialogs.Wpf;
namespace SboxCllGui;
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
}
//============================================================
// Button Clicks
//============================================================
private void BtnExtract_Click(object sender, RoutedEventArgs e)
{
var cllPath = PickFileToOpen("CLL Files|*.*");
if (string.IsNullOrEmpty(cllPath)) return;
var folderPath = PickFolder();
if (string.IsNullOrEmpty(folderPath)) return;
try
{
var cll = CllCodec.ExtractCll(cllPath, folderPath);
TxtPackageIdent.Text = cll.PackageIdent;
TxtCompilerSettings.Text = cll.CompilerSettings;
TxtProjectReferences.Text = cll.ProjectReferences;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void BtnPack_Click(object sender, RoutedEventArgs e)
{
var folderToPack = PickFolder();
if (string.IsNullOrEmpty(folderToPack)) return;
var outputCllFile = PickFileToSave("CLL Files|*.cll|All Files|*.*", "my_package.cll");
if (string.IsNullOrEmpty(outputCllFile)) return;
try
{
CllCodec.PackCll(
folderToPack,
outputCllFile,
TxtPackageIdent.Text,
TxtCompilerSettings.Text,
TxtProjectReferences.Text
);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
//============================================================
// Dialogs
//============================================================
private string? PickFileToOpen(string filter)
{
var dlg = new OpenFileDialog
{
Filter = filter,
FilterIndex = 1
};
return dlg.ShowDialog() == true ? dlg.FileName : null;
}
private string? PickFileToSave(string filter, string defaultFileName)
{
var dlg = new SaveFileDialog
{
Filter = filter,
FileName = defaultFileName
};
return dlg.ShowDialog() == true ? dlg.FileName : null;
}
private string? PickFolder()
{
var dlg = new VistaFolderBrowserDialog
{
Description = "Select a folder",
UseDescriptionForTitle = true,
ShowNewFolderButton = true
};
return dlg.ShowDialog(this) == true ? dlg.SelectedPath : null;
}
}