loupiottes/DMX-2.0/Main.cs
tzim eab625a3bf * Conduite.cs: Suppression d'une alerte a la compilation
* MainWindow.cs: Ajout de l'option pour ouverture de fichier au
  lancement
Meilleure gestion des erreurs sur fichier

* DMX-2.0.csproj: supression des params en ligne de commande sur debug

* Main.cs: pas de webserver par défaut
Ajout de l'option pour ouverture de fichier au lancement

* gui.stetic:
2014-05-08 22:13:55 +00:00

117 lines
No EOL
3.2 KiB
C#

/*
Copyright (C) Arnaud Houdelette 2012-2014
Copyright (C) Emmanuel Langlois 2012-2014
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using Gtk;
namespace DMX2
{
class MainClass
{
public static void Main (string[] args)
{
bool fullscreen = false, aguibtn = false;
WebServer ws = null; bool webserv = false;
System.IO.FileInfo openfile=null;
// Traitement des options en ligne de commande :
foreach (string arg in args) {
switch (arg) {
case "fullscreen":
case "fs":
fullscreen = true;
break;
case "aguibtn":
aguibtn=true;
break;
case "ws":
webserv = true;
break;
default:
if(System.IO.File.Exists(arg))
openfile = new System.IO.FileInfo(arg);
break;
}
}
if(webserv) ws = new WebServer();
// Initialisation GTK#
Application.Init ();
// Repertoire courrant est celui de l'executable
System.IO.Directory.SetCurrentDirectory (
(new System.IO.FileInfo (
System.Reflection.Assembly.GetExecutingAssembly ().Location
)).DirectoryName
);
// Chargement du style GTK
if (System.IO.File.Exists ("style.gtkrc"))
Gtk.Rc.Parse ("style.gtkrc");
else
using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("style.gtkrc"))
using (System.IO.TextReader reader = new System.IO.StreamReader(stream))
Gtk.Rc.ParseString (reader.ReadToEnd ());
// Force l'instanciation du handle midi.
//IntPtr ptr = MidiEventProvider.MidiSeqHandle.Handle;
// Creation de la fenetre principale
MainWindow win = new MainWindow ();
// application des options
if(fullscreen) win.ToggleFullscreen();
if(aguibtn) win.AfficheBoutonACGUI();
if (openfile!=null) win.OpenFile(openfile);
// Gestion des erreurs non traitées dans l'interface
GLib.ExceptionManager.UnhandledException += HandleUnhandledException;
// Lancement
win.Show ();
Application.Run ();
// Nettoyage
if (Conduite.Courante != null) {
Conduite.Courante.Dispose ();
}
if(ws!=null) ws.Dispose();
}
static void HandleUnhandledException (GLib.UnhandledExceptionArgs args)
{
// En cas d'erreur non traitée : on affiche et on demande ...
var dlg = new Dialog ("Erreur !", null, DialogFlags.Modal);
dlg.AddButton ("Continuer ..." , ResponseType.Cancel ).GrabDefault();
dlg.AddButton ("Fermer l'application" , ResponseType.Close );
dlg.VBox.Add (new Label (args.ExceptionObject.ToString()));
dlg.VBox.ShowAll ();
// Si l'utilisateur a clique sur le bon bouton, on continue comme si de rien n'etait...
args.ExitApplication= (ResponseType)dlg.Run() == ResponseType.Close ;
dlg.Destroy();
}
}
}