Skip to content

Commit 9f6dae1

Browse files
Partial implementation.
1 parent 36f4286 commit 9f6dae1

4 files changed

Lines changed: 101 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,4 @@ paket-files/
260260
__pycache__/
261261
*.pyc
262262
/Tools/qemu-img-win-x64-2_3_0.zip
263+
/Tools/qemu-img-win-x64-2_3_0/test.vdi

AnyConvertVM.csproj

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,28 @@
9999
<ItemGroup>
100100
<None Include="App.config" />
101101
</ItemGroup>
102+
<ItemGroup>
103+
<None Include="Tools\qemu-img-win-x64-2_3_0\libgcc_s_sjlj-1.dll">
104+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
105+
</None>
106+
<None Include="Tools\qemu-img-win-x64-2_3_0\libglib-2.0-0.dll">
107+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
108+
</None>
109+
<None Include="Tools\qemu-img-win-x64-2_3_0\libgthread-2.0-0.dll">
110+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
111+
</None>
112+
<None Include="Tools\qemu-img-win-x64-2_3_0\libiconv-2.dll">
113+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
114+
</None>
115+
<None Include="Tools\qemu-img-win-x64-2_3_0\libintl-8.dll">
116+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
117+
</None>
118+
<None Include="Tools\qemu-img-win-x64-2_3_0\libssp-0.dll">
119+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
120+
</None>
121+
<None Include="Tools\qemu-img-win-x64-2_3_0\qemu-img.exe">
122+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
123+
</None>
124+
</ItemGroup>
102125
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
103126
</Project>

ConvertClassActions.cs

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,98 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
35
using System.Linq;
46
using System.Text;
7+
using System.Threading;
58
using System.Threading.Tasks;
69

710
namespace AnyConvertVM
811
{
9-
static class ConvertClassActions
12+
class ConvertClassActions
1013
{
1114

1215
//qemu-img convert -f raw -O qcow2 image.img image.qcow2
1316

1417
public enum FormatType { VDI,VHDX,RAW,QCOW2,VMDK,VHD };
1518

16-
public static void ConvertQEMU(FormatType fromFormat, FormatType toFormat)
19+
public static void ConvertQEMU(FormatType fromFormat, FormatType toFormat, String FromFolderWithFile, String FileName,String SaveFolderPath)
1720
{
1821

1922
try
2023
{
24+
Console.WriteLine("Will start to convert " + fromFormat + " to " + toFormat);
2125

26+
//string fromFormatTextLower = fromFormat.ToString().ToLower();
27+
28+
//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();
31+
Console.WriteLine("ARGs: " + Arguments);
32+
var proc = new Process
33+
{
34+
StartInfo = new ProcessStartInfo
35+
{
36+
FileName = "cmd.exe",
37+
Arguments = Arguments,
38+
UseShellExecute = false,
39+
RedirectStandardOutput = false,
40+
CreateNoWindow = false
41+
42+
}
43+
};
44+
proc.Start();
45+
var std_out_error_reader = proc.StandardError;
46+
var std_out_data_reader = proc.StandardOutput;
47+
WriteToLog(std_out_data_reader);
48+
WriteToLog(std_out_error_reader);
49+
50+
Thread.Sleep(10000);
51+
proc.WaitForExit();
2252
}
2353
catch (Exception ex)
2454
{
2555

2656
}
2757

2858
}
59+
60+
public static void WriteToLog(StreamReader std_out_reader)
61+
{
62+
63+
while (!std_out_reader.EndOfStream)
64+
{
65+
// the point is that the stream does not end until the process has
66+
// finished all of its output.
67+
var nextLine = std_out_reader.ReadLine();
68+
69+
Console.WriteLine(nextLine);
70+
//if (level.Equals("e"))
71+
//{
72+
// Log.Error(TAG + nextLine);
73+
//}
74+
//else Log.Debug(TAG + nextLine);
75+
76+
//if (isVpnError(nextLine))
77+
//{
78+
// Connection.UeAgent.Client.onIpsecError(nextLine);
79+
//}
80+
//else
81+
//{
82+
// if (nextLine.Contains(OpenVPN_Parsing.VPN_CONNECTED))
83+
// {
84+
// Connection.UeAgent.Client.onIpsecConnected();
85+
// Thread.Sleep(3000);
86+
// }
87+
//}
88+
89+
90+
91+
92+
//CreateFile failed on TAP device:
93+
}
94+
// Log.Debug(TAG+ line);
95+
}
2996
}
3097

3198
}

MainWindow.xaml.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ private void Convert_BTN_Click(object sender, RoutedEventArgs e)
7676
try
7777
{
7878

79-
Enum FromFormat=null;
80-
Enum ToFormat = null;
79+
var FromFormat = new ConvertClassActions.FormatType();
80+
var ToFormat = new ConvertClassActions.FormatType();
8181

8282

8383
String SelectedDiskFileNameWithExt = Path.GetFileName(selectFromDisk_TB.Text);
@@ -179,17 +179,17 @@ private void Convert_BTN_Click(object sender, RoutedEventArgs e)
179179
}
180180
#endregion
181181

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

186186
if ( (!ToFormat.Equals(null)) ||
187-
(!FromFormat.Equals(null)) ||
188-
(!SaveFileName.Equals(null))
187+
(!FromFormat.Equals(null)) //||
188+
//(!SaveFileName.Equals(null))
189189
)
190190
{
191191
Console.WriteLine("Let's Convert");
192-
//ConvertClassActions.ConvertQEMU(FromFormat ,ToFormat);
192+
ConvertClassActions.ConvertQEMU(FromFormat ,ToFormat, selectFromDisk_TB.Text, SelectedDiskFileName, saveToDisk_TB.Text);
193193
}
194194

195195

0 commit comments

Comments
 (0)