Skip to content

Commit 522a253

Browse files
Cosmetic changes.
1 parent 9f6dae1 commit 522a253

9 files changed

Lines changed: 134 additions & 35 deletions

File tree

AnyConvertVM.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<Generator>MSBuild:Compile</Generator>
5959
<SubType>Designer</SubType>
6060
</ApplicationDefinition>
61+
<Compile Include="Utils.cs" />
6162
<Page Include="MainWindow.xaml">
6263
<Generator>MSBuild:Compile</Generator>
6364
<SubType>Designer</SubType>
@@ -122,5 +123,9 @@
122123
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
123124
</None>
124125
</ItemGroup>
126+
<ItemGroup>
127+
<Resource Include="Assets\Images\logo.png" />
128+
<Resource Include="Assets\Symbol.png" />
129+
</ItemGroup>
125130
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
126131
</Project>

Assets/Images/logo.png

10.8 KB
Loading

Assets/Symbol.png

5.38 KB
Loading

ConvertClassActions.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,43 @@
33
using System.Diagnostics;
44
using System.IO;
55
using System.Linq;
6+
using System.Reflection;
67
using System.Text;
78
using System.Threading;
89
using System.Threading.Tasks;
10+
using log4net;
911

1012
namespace AnyConvertVM
1113
{
1214
class ConvertClassActions
1315
{
1416

15-
//qemu-img convert -f raw -O qcow2 image.img image.qcow2
17+
18+
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
19+
private const string TAG = "ConvertClassActions: ";
1620

17-
public enum FormatType { VDI,VHDX,RAW,QCOW2,VMDK,VHD };
21+
public enum FormatType { VDI,VHDX,RAW,QCOW2,VMDK,VHD,QED };
1822

1923
public static void ConvertQEMU(FormatType fromFormat, FormatType toFormat, String FromFolderWithFile, String FileName,String SaveFolderPath)
2024
{
2125

2226
try
2327
{
28+
//qemu-img convert -f raw -O qcow2 image.img image.qcow2
29+
// String args = null;
2430
Console.WriteLine("Will start to convert " + fromFormat + " to " + toFormat);
2531

2632
//string fromFormatTextLower = fromFormat.ToString().ToLower();
2733

2834
//Log.Info(TAG + "Trying to update MTU values :" + Settings.MTU);
29-
String Arguments = "/c Tools\\qemu-img-win-x64-2_3_0\\qemu-img.exe convert -f " + fromFormat.ToString().ToLower() + " -O " + toFormat.ToString().ToLower()
30-
+" "+ @FromFolderWithFile + " " + @SaveFolderPath+@"\"+FileName+"."+ toFormat.ToString().ToLower();
35+
36+
string fromFromatArgs = fromFormat.ToString().ToLower();
37+
string toFromatArgs = toFormat.ToString().ToLower();
38+
if (fromFromatArgs.Equals("vhd")) { fromFromatArgs = "vpc"; }
39+
if (toFromatArgs.Equals("vhd")) { toFromatArgs = "vpc"; }
40+
41+
String Arguments = "/c Tools\\qemu-img-win-x64-2_3_0\\qemu-img.exe convert -f " + fromFromatArgs + " -O " + toFromatArgs
42+
+ " "+ @FromFolderWithFile + " " + @SaveFolderPath+@"\"+FileName+"."+ toFormat.ToString().ToLower();
3143
Console.WriteLine("ARGs: " + Arguments);
3244
var proc = new Process
3345
{

MainWindow.xaml

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,46 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:AnyConvertVM"
77
mc:Ignorable="d"
8-
Title="AnyConvertVM" Height="331.381" Width="481.799" ResizeMode="NoResize" Topmost="True" WindowStartupLocation="CenterScreen">
9-
<Grid Background="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}">
8+
Title="AnyConvertVM" Height="419.381" Width="481.799" ResizeMode="NoResize" Topmost="True" WindowStartupLocation="CenterScreen" Icon="Assets/Symbol.png">
9+
<Grid Background="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" Margin="0,0,0,-9">
1010
<Grid.ColumnDefinitions>
11-
<ColumnDefinition Width="293*"/>
12-
<ColumnDefinition Width="70*"/>
13-
<ColumnDefinition Width="113*"/>
11+
<ColumnDefinition Width="387*"/>
12+
<ColumnDefinition Width="Auto"/>
13+
<ColumnDefinition Width="55*"/>
14+
<ColumnDefinition Width="34"/>
1415
</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+
<StackPanel x:Name="FormatRBPanel" HorizontalAlignment="Center" Height="104" Margin="29,122,37,0" VerticalAlignment="Top" Width="321" Background="{DynamicResource {x:Static SystemColors.GradientInactiveCaptionBrushKey}}">
1617
<RadioButton x:Name="VDI_RB" Content="VDI (VirtualBox)" Margin="10,0,0,0" IsChecked="True"/>
1718
<RadioButton x:Name="VHDX_RB" Content="VHDX (Hyper-V)" Margin="10,0,0,0"/>
1819
<RadioButton x:Name="RAW_RB" Content="RAW" Margin="10,0,0,0"/>
1920
<RadioButton x:Name="QCOW2_RB" Content="QCOW2 (KVM, Xen)" Margin="10,0,0,0"/>
2021
<RadioButton x:Name="VMDK_rb" Content="VMDK (VMware)" Margin="10,0,0,0"/>
2122
<RadioButton x:Name="VHD_RB" Content="VHD (Hyper-V)" Margin="10,0,0,0"/>
23+
<RadioButton x:Name="QED_RB" Content="QED (KVM)" Margin="10,0,0,0"/>
2224

2325

2426

2527

2628

2729

2830
</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"/>
31+
<Button x:Name="Convert_BTN" Content="Convert!" HorizontalAlignment="Left" Height="35" Margin="28,301,0,0" VerticalAlignment="Top" Width="99" Background="#FFC8C8C8" Click="Convert_BTN_Click"/>
32+
<TextBox x:Name="selectFromDisk_TB" HorizontalAlignment="Left" Height="19" Margin="28,71,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="322" SelectionBrush="#FF95B7D3" Background="{DynamicResource {x:Static SystemColors.GradientInactiveCaptionBrushKey}}"/>
33+
<Button x:Name="selectFromDisk_BTN" Content="Browse" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="0,71,0,0" Height="19" Grid.Column="2" Click="selectFromDisk_BTN_Click" Grid.ColumnSpan="2"/>
34+
<TextBox x:Name="saveToDisk_TB" HorizontalAlignment="Left" Height="19" Margin="29,254,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="322" Background="{DynamicResource {x:Static SystemColors.GradientInactiveCaptionBrushKey}}"/>
35+
<Button x:Name="saveToDisk_BTN" Content="Browse" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="0,254,0,0" Height="19" RenderTransformOrigin="0.467,2.842" Grid.Column="2" Click="saveToDisk_BTN_Click" Grid.ColumnSpan="2"/>
36+
<Image HorizontalAlignment="Left" Height="50" Margin="10,0,0,0" VerticalAlignment="Top" Width="198" Source="Assets/Images/logo.png"/>
37+
<Label Content="Step 3: Select the location the convert file to be saved" HorizontalAlignment="Left" Margin="28,228,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.449,-0.192" Width="322"/>
38+
<Label Content="Step 4: Let's convert!" HorizontalAlignment="Left" Margin="29,275,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.449,-0.192" Width="322"/>
39+
<Label Content="Step 2: Select the conversion format" HorizontalAlignment="Left" Margin="28,93,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.449,-0.192" Width="322"/>
40+
<Label Content="Step 1: Select the virtual hard disk to convert" HorizontalAlignment="Left" Margin="28,45,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.449,-0.192" Width="322"/>
41+
<Label x:Name="CP_Label" HorizontalAlignment="Center" Margin="59,338,25,10" VerticalAlignment="Center" Width="358" Background="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" Grid.ColumnSpan="3"
42+
CCopyright © 2018 by Sunny Maringanti. Powered by :
43+
<a href=\"http://shyzon.com/\">Shyzon.com</a>
44+
<Hyperlink NavigateUri="http://www.google.com" RequestNavigate="Hyperlink_RequestNavigate">
45+
Click here
46+
</Hyperlink>
47+
</Label>
48+
<!--Content="Copyright © 2018 by Sunny Maringanti. Powered by : Shyzon.com" HorizontalAlignment="Center" Margin="59,338,25,10" VerticalAlignment="Center" Width="358" Background="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" Grid.ColumnSpan="3"/>-->
3449
</Grid>
3550
</Window>

MainWindow.xaml.cs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Reflection;
34
using System.Windows;
45
using System.Windows.Forms;
56
using log4net;
@@ -10,9 +11,19 @@ namespace AnyConvertVM
1011
/// </summary>
1112
public partial class MainWindow : Window
1213
{
14+
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
15+
private const string TAG = "MainWindow: ";
16+
17+
1318
public MainWindow()
1419
{
1520
InitializeComponent();
21+
LoadComponent();
22+
}
23+
24+
private void LoadComponent()
25+
{
26+
CP_Label.Content = "Copyright © 2018 by Sunny Maringanti. Powered by : <a href=\"http://shyzon.com/\">Shyzon.com</a>"; ;
1627
}
1728

1829
private void selectFromDisk_BTN_Click(object sender, RoutedEventArgs e)
@@ -39,7 +50,8 @@ private void selectFromDisk_BTN_Click(object sender, RoutedEventArgs e)
3950
}
4051
catch (Exception ex)
4152
{
42-
53+
Misc.Utils.ExceptionHandleMsg(TAG, "Failed to load the Disk image.", ex);
54+
Misc.Utils.ErrorBox("Failed to load the Disk image.", ex);
4355
}
4456
}
4557

@@ -66,7 +78,8 @@ private void saveToDisk_BTN_Click(object sender, RoutedEventArgs e)
6678
}
6779
catch (Exception ex)
6880
{
69-
81+
Misc.Utils.ExceptionHandleMsg(TAG, "Failed to save the converted Disk image.", ex);
82+
Misc.Utils.ErrorBox("Failed to save the converted Disk image.", ex);
7083
}
7184

7285
}
@@ -81,15 +94,15 @@ private void Convert_BTN_Click(object sender, RoutedEventArgs e)
8194

8295

8396
String SelectedDiskFileNameWithExt = Path.GetFileName(selectFromDisk_TB.Text);
84-
Console.WriteLine("Selected File Name with ext:" + SelectedDiskFileNameWithExt);
97+
Log.Debug(TAG+"Selected File Name with ext:" + SelectedDiskFileNameWithExt);
8598

8699
String SelectedDiskFileName = Path.GetFileNameWithoutExtension(selectFromDisk_TB.Text);
87-
Console.WriteLine("Selected File Name:" + SelectedDiskFileName);
100+
Log.Debug(TAG+"Selected File Name:" + SelectedDiskFileName);
88101

89102
String SelectedDiskFormatName= Path.GetExtension(selectFromDisk_TB.Text);
90-
Console.WriteLine("Selected File Format:" + SelectedDiskFormatName);
103+
Log.Debug(TAG+"Selected File Format:" + SelectedDiskFormatName);
91104

92-
String toExt = null;
105+
93106

94107
if ((selectFromDisk_TB.Text.Equals("Select the virtual hard disk to convert")) ||
95108
(selectFromDisk_TB.Text.Equals(null)) ||
@@ -104,7 +117,9 @@ private void Convert_BTN_Click(object sender, RoutedEventArgs e)
104117
{
105118
System.Windows.MessageBox.Show(Properties.Resources.SelectFolder_msg);
106119
}
120+
107121
#region ToFormatCheck
122+
String toExt = null;
108123
if (VDI_RB.IsChecked.Equals(true))
109124
{
110125
ToFormat = ConvertClassActions.FormatType.VDI;
@@ -139,7 +154,8 @@ private void Convert_BTN_Click(object sender, RoutedEventArgs e)
139154
toExt = ".vhd";
140155
}
141156
#endregion
142-
// Console.WriteLine("Selected File Format:"+ SelectedDiskFormatName);
157+
158+
Log.Debug(TAG+"Selected File Format:"+ SelectedDiskFormatName);
143159

144160
#region FromFormatCheck
145161
if (SelectedDiskFormatName.Equals(".vdi"))
@@ -179,27 +195,21 @@ private void Convert_BTN_Click(object sender, RoutedEventArgs e)
179195
}
180196
#endregion
181197

182-
//String SaveFileName = null;
183-
//SaveFileName = SelectedDiskFileName
184-
// Console.WriteLine("Saved File Name will be: " + SaveFileName);
198+
185199

186-
if ( (!ToFormat.Equals(null)) ||
187-
(!FromFormat.Equals(null)) //||
188-
//(!SaveFileName.Equals(null))
189-
)
200+
if ( (!ToFormat.Equals(null)) || (!FromFormat.Equals(null)))
190201
{
191-
Console.WriteLine("Let's Convert");
202+
Log.Debug(TAG+"Starting conversion...");
192203
ConvertClassActions.ConvertQEMU(FromFormat ,ToFormat, selectFromDisk_TB.Text, SelectedDiskFileName, saveToDisk_TB.Text);
193204
}
194-
195-
196-
197205

198206
}
199207
catch (Exception ex)
200208
{
201-
202-
}
209+
Misc.Utils.ExceptionHandleMsg(TAG, "Failed to convert the disk image.", ex);
210+
Misc.Utils.ErrorBox("Failed to convert the disk image.", ex);
203211
}
212+
213+
}
204214
}
205215
}

Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<data name="AppTitle" xml:space="preserve">
121+
<value>AnyConvertVM</value>
122+
</data>
120123
<data name="SelectFile_msg" xml:space="preserve">
121124
<value>Please select the disk to convert.</value>
122125
</data>

Utils.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Reflection;
3+
using System.Windows.Forms;
4+
using log4net;
5+
6+
namespace Misc
7+
{
8+
class Utils
9+
{
10+
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
11+
private const string TAG = "Utils: ";
12+
13+
14+
public static void ExceptionHandleMsg(String TAGSent, String ErrorMessage, Exception exception)
15+
{
16+
try
17+
{
18+
Log.Error(TAGSent + ErrorMessage);
19+
Log.Error("Exception message: " + exception.Message);
20+
Log.Error("Exception Source: " + exception.Message);
21+
Log.Error("Exception StackTrace: " + exception.StackTrace);
22+
}
23+
catch (Exception ex)
24+
{
25+
Log.Error(TAG + "Exception handling :" + ErrorMessage + exception.Message);
26+
Log.Error(TAGSent + "Exception message: " + ex.Message);
27+
Log.Error("Exception Source: " + ex.Message);
28+
Log.Error("Exception StackTrace: " + ex.StackTrace);
29+
}
30+
}
31+
32+
public static void ErrorBox(string errormsg)
33+
{
34+
MessageBox.Show(errormsg, AnyConvertVM.Properties.Resources.AppTitle , MessageBoxButtons.OK, MessageBoxIcon.Error);
35+
}
36+
37+
public static void ErrorBox(string errormsg,Exception ex)
38+
{
39+
MessageBox.Show(errormsg+"\nException messaage: "+ex, AnyConvertVM.Properties.Resources.AppTitle,
40+
MessageBoxButtons.OK, MessageBoxIcon.Error);
41+
}
42+
43+
}
44+
45+
}

0 commit comments

Comments
 (0)