11using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
5- using System . Threading . Tasks ;
2+ using System . IO ;
63using System . Windows ;
7- using System . Windows . Controls ;
8- using System . Windows . Data ;
9- using System . Windows . Documents ;
10- using System . Windows . Input ;
11- using System . Windows . Media ;
12- using System . Windows . Media . Imaging ;
13- using System . Windows . Navigation ;
14- using System . Windows . Shapes ;
15-
4+ using System . Windows . Forms ;
5+ using log4net ;
166namespace AnyConvertVM
177{
188 /// <summary>
@@ -24,5 +14,192 @@ public MainWindow()
2414 {
2515 InitializeComponent ( ) ;
2616 }
17+
18+ private void selectFromDisk_BTN_Click ( object sender , RoutedEventArgs e )
19+ {
20+ try
21+ {
22+ var fileDialog = new OpenFileDialog ( ) ;
23+ var result = fileDialog . ShowDialog ( ) ;
24+
25+ switch ( result )
26+ {
27+ case System . Windows . Forms . DialogResult . OK :
28+ var file = fileDialog . FileName ;
29+ selectFromDisk_TB . Text = file ;
30+ selectFromDisk_TB . ToolTip = file ;
31+ break ;
32+ case System . Windows . Forms . DialogResult . Cancel :
33+ default :
34+ selectFromDisk_TB . Text = null ;
35+ selectFromDisk_TB . ToolTip = null ;
36+ break ;
37+ }
38+ //selectFromDisk_TB.Text = result.ToString;
39+ }
40+ catch ( Exception ex )
41+ {
42+
43+ }
44+ }
45+
46+ private void saveToDisk_BTN_Click ( object sender , RoutedEventArgs e )
47+ {
48+ try
49+ {
50+ var folderDialog = new FolderBrowserDialog ( ) ;
51+ var result = folderDialog . ShowDialog ( ) ;
52+
53+ switch ( result )
54+ {
55+ case System . Windows . Forms . DialogResult . OK :
56+ var folder = folderDialog . SelectedPath ;
57+ saveToDisk_TB . Text = folder ;
58+ saveToDisk_TB . ToolTip = folder ;
59+ break ;
60+ case System . Windows . Forms . DialogResult . Cancel :
61+ default :
62+ saveToDisk_TB . Text = null ;
63+ saveToDisk_TB . ToolTip = null ;
64+ break ;
65+ }
66+ }
67+ catch ( Exception ex )
68+ {
69+
70+ }
71+
72+ }
73+
74+ private void Convert_BTN_Click ( object sender , RoutedEventArgs e )
75+ {
76+ try
77+ {
78+
79+ Enum FromFormat = null ;
80+ Enum ToFormat = null ;
81+
82+
83+ String SelectedDiskFileNameWithExt = Path . GetFileName ( selectFromDisk_TB . Text ) ;
84+ Console . WriteLine ( "Selected File Name with ext:" + SelectedDiskFileNameWithExt ) ;
85+
86+ String SelectedDiskFileName = Path . GetFileNameWithoutExtension ( selectFromDisk_TB . Text ) ;
87+ Console . WriteLine ( "Selected File Name:" + SelectedDiskFileName ) ;
88+
89+ String SelectedDiskFormatName = Path . GetExtension ( selectFromDisk_TB . Text ) ;
90+ Console . WriteLine ( "Selected File Format:" + SelectedDiskFormatName ) ;
91+
92+ String toExt = null ;
93+
94+ if ( ( selectFromDisk_TB . Text . Equals ( "Select the virtual hard disk to convert" ) ) ||
95+ ( selectFromDisk_TB . Text . Equals ( null ) ) ||
96+ ! File . Exists ( selectFromDisk_TB . Text ) )
97+ {
98+ System . Windows . MessageBox . Show ( Properties . Resources . SelectFile_msg ) ;
99+ }
100+
101+ if ( ( saveToDisk_TB . Text . Equals ( "Select the location the convert file to be saved" ) ) ||
102+ ( saveToDisk_TB . Text . Equals ( null ) ) ||
103+ ! Directory . Exists ( saveToDisk_TB . Text ) )
104+ {
105+ System . Windows . MessageBox . Show ( Properties . Resources . SelectFolder_msg ) ;
106+ }
107+ #region ToFormatCheck
108+ if ( VDI_RB . IsChecked . Equals ( true ) )
109+ {
110+ ToFormat = ConvertClassActions . FormatType . VDI ;
111+ toExt = ".vdi" ;
112+
113+ }
114+ else if ( VHDX_RB . IsChecked . Equals ( true ) )
115+ {
116+ ToFormat = ConvertClassActions . FormatType . VHDX ;
117+ toExt = ".vhdx" ;
118+ }
119+ else if ( RAW_RB . IsChecked . Equals ( true ) )
120+ {
121+ ToFormat = ConvertClassActions . FormatType . RAW ;
122+ toExt = ".raw" ;
123+
124+ }
125+ else if ( QCOW2_RB . IsChecked . Equals ( true ) )
126+ {
127+ ToFormat = ConvertClassActions . FormatType . QCOW2 ;
128+ toExt = ".qcow2" ;
129+
130+ }
131+ else if ( VMDK_rb . IsChecked . Equals ( true ) )
132+ {
133+ ToFormat = ConvertClassActions . FormatType . VMDK ;
134+ toExt = ".vmdk" ;
135+ }
136+ else if ( VHD_RB . IsChecked . Equals ( true ) )
137+ {
138+ ToFormat = ConvertClassActions . FormatType . VHD ;
139+ toExt = ".vhd" ;
140+ }
141+ #endregion
142+ // Console.WriteLine("Selected File Format:"+ SelectedDiskFormatName);
143+
144+ #region FromFormatCheck
145+ if ( SelectedDiskFormatName . Equals ( ".vdi" ) )
146+ {
147+ FromFormat = ConvertClassActions . FormatType . VDI ;
148+ }
149+ else if ( SelectedDiskFormatName . Equals ( ".vhdx" ) )
150+ {
151+ FromFormat = ConvertClassActions . FormatType . VHDX ;
152+
153+ }
154+ else if ( SelectedDiskFormatName . Equals ( ".raw" ) )
155+ {
156+ FromFormat = ConvertClassActions . FormatType . RAW ;
157+
158+
159+ }
160+ else if ( SelectedDiskFormatName . Equals ( ".qcow2" ) )
161+ {
162+ FromFormat = ConvertClassActions . FormatType . QCOW2 ;
163+
164+
165+ }
166+ else if ( SelectedDiskFormatName . Equals ( ".vmdk" ) )
167+ {
168+ FromFormat = ConvertClassActions . FormatType . VMDK ;
169+
170+ }
171+ else if ( SelectedDiskFormatName . Equals ( ".vhd" ) )
172+ {
173+ FromFormat = ConvertClassActions . FormatType . VHD ;
174+
175+ }
176+ else
177+ {
178+ System . Windows . MessageBox . Show ( Properties . Resources . WrongFileFormat_msg ) ;
179+ }
180+ #endregion
181+
182+ String SaveFileName = null ;
183+ SaveFileName = SelectedDiskFileName + toExt ;
184+ Console . WriteLine ( "Saved File Name will be: " + SaveFileName ) ;
185+
186+ if ( ( ! ToFormat . Equals ( null ) ) ||
187+ ( ! FromFormat . Equals ( null ) ) ||
188+ ( ! SaveFileName . Equals ( null ) )
189+ )
190+ {
191+ Console . WriteLine ( "Let's Convert" ) ;
192+ //ConvertClassActions.ConvertQEMU(FromFormat ,ToFormat);
193+ }
194+
195+
196+
197+
198+ }
199+ catch ( Exception ex )
200+ {
201+
202+ }
203+ }
27204 }
28205}
0 commit comments