Skip to content

Commit 36f4286

Browse files
Initial update
1 parent 1944e83 commit 36f4286

15 files changed

Lines changed: 322 additions & 49 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,5 @@ paket-files/
258258

259259
# Python Tools for Visual Studio (PTVS)
260260
__pycache__/
261-
*.pyc
261+
*.pyc
262+
/Tools/qemu-img-win-x64-2_3_0.zip

AnyConvertVM.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@
3434
<WarningLevel>4</WarningLevel>
3535
</PropertyGroup>
3636
<ItemGroup>
37+
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
38+
<HintPath>packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
39+
</Reference>
3740
<Reference Include="System" />
3841
<Reference Include="System.Data" />
42+
<Reference Include="System.Windows.Forms" />
3943
<Reference Include="System.Xml" />
4044
<Reference Include="Microsoft.CSharp" />
4145
<Reference Include="System.Core" />
@@ -62,6 +66,7 @@
6266
<DependentUpon>App.xaml</DependentUpon>
6367
<SubType>Code</SubType>
6468
</Compile>
69+
<Compile Include="ConvertClassActions.cs" />
6570
<Compile Include="MainWindow.xaml.cs">
6671
<DependentUpon>MainWindow.xaml</DependentUpon>
6772
<SubType>Code</SubType>
@@ -85,6 +90,7 @@
8590
<Generator>ResXFileCodeGenerator</Generator>
8691
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
8792
</EmbeddedResource>
93+
<None Include="packages.config" />
8894
<None Include="Properties\Settings.settings">
8995
<Generator>SettingsSingleFileGenerator</Generator>
9096
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

ConvertClassActions.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace AnyConvertVM
8+
{
9+
static class ConvertClassActions
10+
{
11+
12+
//qemu-img convert -f raw -O qcow2 image.img image.qcow2
13+
14+
public enum FormatType { VDI,VHDX,RAW,QCOW2,VMDK,VHD };
15+
16+
public static void ConvertQEMU(FormatType fromFormat, FormatType toFormat)
17+
{
18+
19+
try
20+
{
21+
22+
}
23+
catch (Exception ex)
24+
{
25+
26+
}
27+
28+
}
29+
}
30+
31+
}

MainWindow.xaml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
1-
<Window x:Class="AnyConvertVM.MainWindow"
1+
<Window x:Name="AnyConvertVM_TitleBar" x:Class="AnyConvertVM.MainWindow"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:AnyConvertVM"
77
mc:Ignorable="d"
8-
Title="MainWindow" Height="450" Width="800">
9-
<Grid>
10-
8+
Title="AnyConvertVM" Height="331.381" Width="481.799" ResizeMode="NoResize" Topmost="True" WindowStartupLocation="CenterScreen">
9+
<Grid Background="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}">
10+
<Grid.ColumnDefinitions>
11+
<ColumnDefinition Width="293*"/>
12+
<ColumnDefinition Width="70*"/>
13+
<ColumnDefinition Width="113*"/>
14+
</Grid.ColumnDefinitions>
15+
<StackPanel x:Name="FormatRBPanel" HorizontalAlignment="Center" Height="93" Margin="30,62,10,0" VerticalAlignment="Top" Width="323" Background="{DynamicResource {x:Static SystemColors.GradientInactiveCaptionBrushKey}}" Grid.ColumnSpan="2">
16+
<RadioButton x:Name="VDI_RB" Content="VDI (VirtualBox)" Margin="10,0,0,0" IsChecked="True"/>
17+
<RadioButton x:Name="VHDX_RB" Content="VHDX (Hyper-V)" Margin="10,0,0,0"/>
18+
<RadioButton x:Name="RAW_RB" Content="RAW" Margin="10,0,0,0"/>
19+
<RadioButton x:Name="QCOW2_RB" Content="QCOW2 (KVM, Xen)" Margin="10,0,0,0"/>
20+
<RadioButton x:Name="VMDK_rb" Content="VMDK (VMware)" Margin="10,0,0,0"/>
21+
<RadioButton x:Name="VHD_RB" Content="VHD (Hyper-V)" Margin="10,0,0,0"/>
22+
23+
24+
25+
26+
27+
28+
</StackPanel>
29+
<Button x:Name="Convert_BTN" Content="Convert!" HorizontalAlignment="Left" Height="35" Margin="30,223,0,0" VerticalAlignment="Top" Width="99" Background="{DynamicResource {x:Static SystemColors.ScrollBarBrushKey}}" Click="Convert_BTN_Click"/>
30+
<TextBox x:Name="selectFromDisk_TB" HorizontalAlignment="Left" Height="19" Margin="30,23,0,0" TextWrapping="Wrap" Text="Select the virtual hard disk to convert" VerticalAlignment="Top" Width="322" SelectionBrush="#FF95B7D3" Background="{DynamicResource {x:Static SystemColors.GradientInactiveCaptionBrushKey}}" Grid.ColumnSpan="2"/>
31+
<Button x:Name="selectFromDisk_BTN" Content="Browse" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="16,23,0,0" Height="19" Grid.Column="2" Click="selectFromDisk_BTN_Click"/>
32+
<TextBox x:Name="saveToDisk_TB" HorizontalAlignment="Left" Height="19" Margin="30,175,0,0" TextWrapping="Wrap" Text="Select the location the convert file to be saved" VerticalAlignment="Top" Width="322" Background="{DynamicResource {x:Static SystemColors.GradientInactiveCaptionBrushKey}}" Grid.ColumnSpan="2"/>
33+
<Button x:Name="saveToDisk_BTN" Content="Browse" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="16,175,0,0" Height="19" RenderTransformOrigin="0.467,2.842" Grid.Column="2" Click="saveToDisk_BTN_Click"/>
1134
</Grid>
1235
</Window>

MainWindow.xaml.cs

Lines changed: 190 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
2+
using System.IO;
63
using 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;
166
namespace 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

Comments
 (0)