-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.cs
318 lines (266 loc) · 7.9 KB
/
MainWindow.cs
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
using System;
using Gtk;
using System.Diagnostics;
using System.IO;
using LinXbox360isoBurner;
using System.Media;
using Mono.Unix;
public partial class MainWindow: Gtk.Window
{
bool dryrun;
Process process;
BurningWindow burning;
Conf config;
StreamWriter logwriter;
Gnome.Vfs.VolumeMonitor vm;
DVDdrive dvddrive;
bool BurnSensetive
{
set
{
button_ok.Sensitive = value;
BurnAction.Sensitive = value;
}
}
string logstring
{
set
{
if (config.log)
{
logwriter.WriteLine(value);
}
}
}
// MainWindow Constructor
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
entry_dvd.Changed += OnEntry_dvdChanged;
// Adds "*.dvd" fillter to FileChooserDialog
FileFilter filter = new FileFilter();
filter.Name="*.dvd";
filter.AddPattern("*.dvd");
filechooserbutton.AddFilter(filter);
UnixUserInfo user = UnixUserInfo.GetRealUser();
// Checks existing of configuration file and loads configuration of the programm
if (!Directory.Exists(user.HomeDirectory + "/.linxbox360burner")) Directory.CreateDirectory(user.HomeDirectory + "/.linxbox360burner");
if (!File.Exists(user.HomeDirectory + "/.linxbox360burner/conf"))
{
config = new Conf();
config.Commit();
}
else
{
config = new Conf(user.HomeDirectory + "/.linxbox360burner/conf");
}
if (config.dvdrwremember) entry_dvd.Text = config.dvdrw;
dvddrive = new DVDdrive (entry_dvd.Text);
dvddrive.GetMediaInfo();
Gnome.Vfs.Vfs.Initialize();
vm = Gnome.Vfs.VolumeMonitor.Get();
vm.VolumeMounted += delegate(object o, Gnome.Vfs.VolumeMountedArgs args) {
DriveStateChanged();
};
vm.VolumeUnmounted += delegate(object o, Gnome.Vfs.VolumeUnmountedArgs args) {
DriveStateChanged();
};
}
// Starts burning process
protected virtual void OnButtonOkClicked (object sender, System.EventArgs e)
{
// Check .dvd file
FileInfo dvdfile = new FileInfo(entry.Text);
if (!dvdfile.Exists)
{
FileError fileerrorwindow = new FileError();
fileerrorwindow.Show();
return;
}
StreamReader dvdreader = new StreamReader(dvdfile.FullName);
string layerbreak = dvdreader.ReadLine();
int temp = layerbreak.IndexOf('=');
layerbreak = layerbreak.Substring(temp + 1);
string isoname = dvdreader.ReadLine();
isoname = dvdfile.DirectoryName + "/" + isoname;
FileInfo iso = new FileInfo(isoname);
if (!iso.Exists)
{
FileError fileerrorwindow = new FileError();
fileerrorwindow.Show();
return;
}
isoname="\""+isoname+"\"";
//Added for XGD3 format support
if (iso.Length >= 8547991552)
{
if (!Truncate(isoname))
{
FileError fileerrorwindow = new FileError();
fileerrorwindow.Show();
return;
}
layerbreak = "2086912";
}
string dvdrw = entry_dvd.Text;
string speed = combobox_speed.ActiveText;
string argstring ="";
if (dryrun) argstring +="-dry-run ";
argstring +="-use-the-force-luke=dao -use-the-force-luke=break:"
+ layerbreak + " -dvd-compat -speed=" + speed + " -Z " + dvdrw + "=" + isoname;
// Creates "growisofs" process and redirect its output to this programm
process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.EnableRaisingEvents = true;
process.OutputDataReceived += new DataReceivedEventHandler(HandleOutputDataReceived);
process.ErrorDataReceived += new DataReceivedEventHandler(HandleErrorDataReceived);
process.Exited += new EventHandler(HandleExited);
process.StartInfo.Arguments = argstring;
process.StartInfo.FileName = "growisofs";
// process.StartInfo.Arguments ="mail.ru -c 10"; // test strings
// process.StartInfo.FileName = "ping"; // test strings
// Check logfile size
bool append = false;
FileInfo f = new FileInfo (config.logpath);
if (f.Exists)
{
if (config.logsize > (f.Length/1000)) append = true;
}
logwriter = new StreamWriter(config.logpath, append);
logwriter.AutoFlush = true;
logstring = "============ <START> ============";
logstring = "Start burning " + DateTime.Now.ToString();
burning = new BurningWindow(ref process);
burning.Destroyed += delegate(object send, EventArgs c) {this.Visible = true;};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
this.Visible = false;
burning.ShowAll();
}
// Next three methods are process event handlers
protected void HandleOutputDataReceived(object sender, DataReceivedEventArgs e)
{
burning.Label_burn = e.Data.ToString();
logstring = e.Data.ToString();
}
protected void HandleErrorDataReceived(object sender, DataReceivedEventArgs e)
{
burning.Label_burn = e.Data.ToString();
logstring = e.Data.ToString();
}
protected void HandleExited(object sender, EventArgs e)
{
burning.ButtonHeadlerChange();
if (process.ExitCode == 0)
{
burning.Title = "Burning sucsesfull";
burning.Label_burn = "Burning sucsesfull";
logstring = "Burning sucsesfull " + DateTime.Now.ToString();
if (config.dvdrwremember == true) {config.dvdrw = entry_dvd.Text; config.Commit();}
SystemSounds.Asterisk.Play();
}
if (process.ExitCode != 0)
{
burning.Title = "Error";
SystemSounds.Hand.Play();
}
burning.Button_text = "Close";
logstring = "Burning stops " + DateTime.Now.ToString();
logstring = "============ <END> ============";
logstring = "";
logwriter.Dispose();
burning.trayicon.Blinking = true;
}
// Next methods are different GUI events handlers
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
protected virtual void OnButtonExitClicked (object sender, System.EventArgs e)
{
Application.Quit();
}
protected virtual void OnFilechooserbuttonSelectionChanged (object sender, System.EventArgs e)
{
entry.Text = filechooserbutton.Filename;
}
protected virtual void OnCheckbuttonDryrunPressed (object sender, System.EventArgs e)
{
dryrun = !dryrun;
}
protected virtual void OnEntryChanged (object sender, System.EventArgs e)
{
TryState();
}
protected void OnEntry_dvdChanged (object sender, System.EventArgs e)
{
DriveStateChanged();
}
protected virtual void OnButtonAutodvdrwClicked (object sender, System.EventArgs e)
{
Dvdrwchoose dialog = new Dvdrwchoose();
dialog.Destroyed += delegate {if (dialog.dvdrw != null) entry_dvd.Text = dialog.dvdrw;
else entry_dvd.Text = "/dev/";};
dialog.Visible = true;
}
protected virtual void OnAboutActionActivated (object sender, System.EventArgs e)
{
About ab = new About();
ab.Visible = true;
}
protected virtual void OnPreferencesActionActivated (object sender, System.EventArgs e)
{;
Preferences prefs = new Preferences(config);
this.Sensitive = false;
prefs.Destroyed+= delegate(object send, EventArgs c)
{
this.Sensitive = true;
};
prefs.Visible = true;
}
static bool Truncate (string iso)
{
bool result = true;
Process truncate = new Process();
truncate.StartInfo.FileName="truncate";
string arg = "--size=8547991552 "+iso;
truncate.StartInfo.Arguments=arg;
truncate.Exited += delegate { if (truncate.ExitCode !=0) result=false;};
truncate.Start();
truncate.WaitForExit();
return result;
}
void DriveStateChanged()
{
ListStore ls = new ListStore(typeof(string));
combobox_speed.Model = ls;
dvddrive = new DVDdrive(entry_dvd.Text);
dvddrive.GetMediaInfo();
if (dvddrive.DiskInserted)
{
foreach (string d in dvddrive.WriteSpeeds)
{
combobox_speed.AppendText(d);
}
combobox_speed.Active = 0;
combobox_speed.Sensitive = true;
}
else
{
combobox_speed.AppendText("No media");
combobox_speed.Active = 0;
combobox_speed.Sensitive = false;
}
ls.Dispose();
TryState();
}
void TryState()
{
if (File.Exists(entry.Text) && dvddrive.DiskInserted) BurnSensetive = true;
else BurnSensetive = false;
}
}