// MainWindow.cs created with MonoDevelop // User: aberlanas at 8:05 06/11/2009 // // To change standard headers go to Edit->Preferences->Coding->Standard Headers // using System; using Gtk; using lliurex.imagewriter; using System.Collections; using System.Timers; using Pango; public partial class MainWindow: Gtk.Window { private System.Collections.Generic.Dictionary dictionaryDevices; private string currentDevice; private System.Diagnostics.Process ddproc; private bool bogus; public MainWindow (string srcimage,bool bogus): base (Gtk.WindowType.Toplevel) { Build (); this.bogus=bogus; // Initiliazing devices_array dictionaryDevices = MainClass.replenishDevices(); fillDeviceChooser(); if (srcimage!="") { if(System.IO.File.Exists(srcimage)) { System.Console.WriteLine("Using " + srcimage + " as source"); filechooserbutton_source.SetFilename(srcimage); } } Gtk.FileFilter[] simpleFilter = new FileFilter[5]; simpleFilter[0] = new FileFilter(); simpleFilter[0].Name= "Images (*.img)"; simpleFilter[0].AddPattern("*.img"); filechooserbutton_source.AddFilter(simpleFilter[0]); simpleFilter[1] = new FileFilter(); simpleFilter[1].AddPattern("*.dsk"); simpleFilter[1].Name = "Floppy (*.dsk)"; filechooserbutton_source.AddFilter(simpleFilter[1]); simpleFilter[2] = new FileFilter(); simpleFilter[2].AddPattern("*.image"); simpleFilter[2].Name = "Images (*.image)"; filechooserbutton_source.AddFilter(simpleFilter[2]); simpleFilter[3] = new FileFilter(); simpleFilter[3].AddPattern("*.usb"); simpleFilter[3].Name = "USB (*.usb)"; filechooserbutton_source.AddFilter(simpleFilter[3]); simpleFilter[4] = new FileFilter(); simpleFilter[4].AddPattern("*"); simpleFilter[4].Name= "All"; filechooserbutton_source.AddFilter(simpleFilter[4]); } protected void OnDeleteEvent (object sender, DeleteEventArgs a) { Application.Quit (); a.RetVal = true; } protected bool updateEvilProgressBar() { bool ret = true; if(ddproc.HasExited) { ret = false; progressbarevil.Fraction=0.0; label_message.Text=Mono.Unix.Catalog.GetString("Finished"); button_write.Sensitive = true; } else { progressbarevil.Pulse(); } return ret; } protected virtual void OnButtonWriteClicked (object sender, System.EventArgs e) { if(filechooserbutton_source.Filename == null || combobox_destiny.ActiveText == null) { WindowAttention windowAttention = new WindowAttention(); windowAttention.Show(); } else { if(bogus)currentDevice="/dev/null"; Mono.Unix.UnixFileInfo myFileInfo = new Mono.Unix.UnixFileInfo(currentDevice); if (! myFileInfo.CanAccess(Mono.Unix.Native.AccessModes.W_OK)) { label_message.Text = Mono.Unix.Catalog.GetString("Not have permissions to write : "+myFileInfo.Name); label_message.ModifyFont(FontDescription.FromString("Sans 14")); return ; } //label_message.Text="Working in Progress ... Please Wait"; label_message.Text=Mono.Unix.Catalog.GetString("Work in Progress... Please Wait"); label_message.ModifyFont(FontDescription.FromString("Sans 14")); // Progressbar GLib.Timeout.Add(100, new GLib.TimeoutHandler(updateEvilProgressBar)); System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = "/usr/bin/lliurex-umount-by-device"; proc.StartInfo.Arguments = currentDevice; proc.Start(); proc.WaitForExit(15000); System.Console.WriteLine("Devices umounted"); proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents=false; proc.StartInfo.FileName = "dd"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.Arguments = "if="+filechooserbutton_source.Filename+" of="+currentDevice; //proc.Exited+=new EventHandler(this.OnDdExit); proc.EnableRaisingEvents = true; button_write.Sensitive = false; ddproc=proc; proc.Start(); } } protected virtual void OnFilechooserbuttonSourceSelectionChanged (object sender, System.EventArgs e) { bool attentionMessage = lliurex.imagewriter.MainClass.testImageFile(filechooserbutton_source.Filename); if (attentionMessage) { Console.WriteLine("Cuidadin"); } fillDeviceChooser(); label_message.Text=Mono.Unix.Catalog.GetString("Ready to burn"); } private void fillDeviceChooser() { ((Gtk.ListStore)combobox_destiny.Model).Clear(); foreach (System.Collections.Generic.KeyValuePair dicEntry in dictionaryDevices) { System.Console.WriteLine("Adding device: " + dicEntry.Value); combobox_destiny.AppendText(dicEntry.Value); } // If we have a selected image we must "recomends" a Device System.Console.WriteLine("Setting default device"); if (filechooserbutton_source.Filename != null){ TreeIter myIter; combobox_destiny.Model.GetIterFirst(out myIter); combobox_destiny.SetActiveIter(myIter); System.Console.WriteLine(combobox_destiny.ActiveText); } } protected virtual void OnButtonExitClicked (object sender, System.EventArgs e) { Application.Quit (); } protected virtual void OnComboboxDestinyChanged (object sender, System.EventArgs e) { foreach (System.Collections.Generic.KeyValuePair dicEntry in dictionaryDevices) { if (combobox_destiny.ActiveText == dicEntry.Value) { currentDevice = dicEntry.Key; break; } } } }