public static void Main(string[] args) { string HOMEDIR = Environment.GetEnvironmentVariable("HOME"); string USER = Environment.GetEnvironmentVariable("USER"); ConfigDirectory = HOMEDIR + "/.config/gfax"; SpoolDirectory = HOMEDIR + "/.local/share/gfax/spool"; pargs = args; // TODO put this is try/catch if ( !Directory.Exists(ConfigDirectory)) { if ( !Directory.Exists(HOMEDIR + "/.config")) { Directory.CreateDirectory(HOMEDIR + "/.config"); } // Move data from old ~/.etc directory if ( Directory.Exists(HOMEDIR + "/.etc/gfax")) { Directory.Move(HOMEDIR + "/.etc/gfax", ConfigDirectory); } else { Directory.CreateDirectory(ConfigDirectory); } } if ( !Directory.Exists(HOMEDIR + "/.local/share/gfax/spool") ) { if ( !Directory.Exists(HOMEDIR + "/.local/share/gfax") ) { if ( !Directory.Exists(HOMEDIR + "/.local/share") ) { if ( !Directory.Exists(HOMEDIR + "/.local") ) Directory.CreateDirectory(HOMEDIR + "/.local"); Directory.CreateDirectory(HOMEDIR + "/.local/share"); } Directory.CreateDirectory(HOMEDIR + "/.local/share/gfax"); } Directory.CreateDirectory(HOMEDIR + "/.local/share/gfax/spool"); Directory.CreateDirectory(HOMEDIR + "/.local/share/gfax/spool/doneq"); Directory.CreateDirectory(HOMEDIR + "/.local/share/gfax/spool/recq"); } // Clean out the spool/tif directory - incoming faxes if ( !Directory.Exists(HOMEDIR + "/.local/share/gfax/spool/tif")) { Directory.CreateDirectory(HOMEDIR + "/.local/share/gfax/spool/tif"); } else { Directory.Delete(HOMEDIR + "/.local/share/gfax/spool/tif/", true); Directory.CreateDirectory(HOMEDIR + "/.local/share/gfax/spool/tif"); } // Initialize GETTEXT Catalog.Init ("gfax", Defines.GNOME_LOCALE_DIR); // handle command line args ourselves for (int i=0; i < args.Length; i++ ) { //Console.WriteLine("{0} {1}", i, args[i]); switch (args[i]) { case "--help" : Console.WriteLine (Catalog.GetString("Gfax help...")); Console.WriteLine ("Gfax spool dir -> {0}", SpoolDirectory); break; case "-f" : // file name is present filename = args[i+1]; break; //case "-q" : // immediately quit after sending fax // filename = args[i+1]; // break; default: if (File.Exists(args[i])) filename = args[i]; break; } } try { if ( Settings.RunSetupAtStart ) { // Set some default preferences. Settings.TransmitAgent = "efax"; Settings.SendNow = true; Settings.EfaxModemDevice = "ttyS0"; Settings.RefreshQueueInterval = 15; Settings.RefreshQueueEnabled = true; } } catch (Exception e) { //TODO HIG love required G_Message gm = new G_Message( Catalog.GetString( @"Gconfd cannot find your settings. If you are running Gfax immediately after an installation, you may have to log out and log back in again."), TOPLEVEL); Console.WriteLine("Exception in main.cs {0}", e); Environment.Exit(0); } // If we have a file name run the send dialog if (filename != null) { GfaxSend sd = new GfaxSend (filename, args); FileInfo f = new FileInfo(filename); // send the faxes if (sd.DoSend) { fromSendWizard = true; // Start the fax daemon if efax if (Settings.TransmitAgent == "efax") { efax = new Efax(); efax.run_efaxd(); } Fax.sendfax(filename); // delete the spool file (~.local/share/gfax/spool/D.*) if (File.Exists(String.Concat(SpoolDirectory, "/", f.Name))) File.Delete(String.Concat(SpoolDirectory, "/", f.Name)); //if (!quitAfterSend) { //Gfax gf = new Gfax (filename, args); //} } // delete the spool file that gfax created if it exists if (File.Exists(String.Concat("/var/spool/gfax/", USER, "/", f.Name))) File.Delete(String.Concat("/var/spool/gfax/", USER, "/", f.Name)); }else { // We need /var/spool/gfax/<user> to exsist and be 0777 perms //ACCESSPERMS = 0777 if ( !Directory.Exists("/var/spool/gfax/" + USER)) { Directory.CreateDirectory("/var/spool/gfax/" + USER); } Mono.Unix.Native.Syscall.chmod("/var/spool/gfax/" + USER, Mono.Unix.Native.FilePermissions.ACCESSPERMS); FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = "/var/spool/gfax/" + USER; watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; // Only watch text files. watcher.Filter = "*"; watcher.Created += new FileSystemEventHandler(TIOnChanged); // Begin watching. watcher.EnableRaisingEvents = true; // Start the fax daemon if efax if (Settings.TransmitAgent == "efax") { efax = new Efax(); efax.run_efaxd(); } Gfax gf = new Gfax (filename, args); } }
public static void Main(string[] args) { string HOMEDIR = Environment.GetEnvironmentVariable("HOME"); string USER = Environment.GetEnvironmentVariable("USER"); ConfigDirectory = HOMEDIR + "/.config/gfax"; SpoolDirectory = HOMEDIR + "/.local/share/gfax/spool"; pargs = args; // TODO put this is try/catch if (!Directory.Exists(ConfigDirectory)) { if (!Directory.Exists(HOMEDIR + "/.config")) { Directory.CreateDirectory(HOMEDIR + "/.config"); } // Move data from old ~/.etc directory if (Directory.Exists(HOMEDIR + "/.etc/gfax")) { Directory.Move(HOMEDIR + "/.etc/gfax", ConfigDirectory); } else { Directory.CreateDirectory(ConfigDirectory); } } if (!Directory.Exists(HOMEDIR + "/.local/share/gfax/spool")) { if (!Directory.Exists(HOMEDIR + "/.local/share/gfax")) { if (!Directory.Exists(HOMEDIR + "/.local/share")) { if (!Directory.Exists(HOMEDIR + "/.local")) { Directory.CreateDirectory(HOMEDIR + "/.local"); } Directory.CreateDirectory(HOMEDIR + "/.local/share"); } Directory.CreateDirectory(HOMEDIR + "/.local/share/gfax"); } Directory.CreateDirectory(HOMEDIR + "/.local/share/gfax/spool"); Directory.CreateDirectory(HOMEDIR + "/.local/share/gfax/spool/doneq"); Directory.CreateDirectory(HOMEDIR + "/.local/share/gfax/spool/recq"); } // Clean out the spool/tif directory - incoming faxes if (!Directory.Exists(HOMEDIR + "/.local/share/gfax/spool/tif")) { Directory.CreateDirectory(HOMEDIR + "/.local/share/gfax/spool/tif"); } else { Directory.Delete(HOMEDIR + "/.local/share/gfax/spool/tif/", true); Directory.CreateDirectory(HOMEDIR + "/.local/share/gfax/spool/tif"); } // Initialize GETTEXT Catalog.Init("gfax", Defines.GNOME_LOCALE_DIR); // handle command line args ourselves for (int i = 0; i < args.Length; i++) { //Console.WriteLine("{0} {1}", i, args[i]); switch (args[i]) { case "--help": Console.WriteLine(Catalog.GetString("Gfax help...")); Console.WriteLine("Gfax spool dir -> {0}", SpoolDirectory); break; case "-f": // file name is present filename = args[i + 1]; break; //case "-q" : // immediately quit after sending fax // filename = args[i+1]; // break; default: if (File.Exists(args[i])) { filename = args[i]; } break; } } try { if (Settings.RunSetupAtStart) { // Set some default preferences. Settings.TransmitAgent = "efax"; Settings.SendNow = true; Settings.EfaxModemDevice = "ttyS0"; Settings.RefreshQueueInterval = 15; Settings.RefreshQueueEnabled = true; } } catch (Exception e) { //TODO HIG love required G_Message gm = new G_Message( Catalog.GetString( @"Gconfd cannot find your settings. If you are running Gfax immediately after an installation, you may have to log out and log back in again."), TOPLEVEL); Console.WriteLine("Exception in main.cs {0}", e); Environment.Exit(0); } // If we have a file name run the send dialog if (filename != null) { GfaxSend sd = new GfaxSend(filename, args); FileInfo f = new FileInfo(filename); // send the faxes if (sd.DoSend) { fromSendWizard = true; // Start the fax daemon if efax if (Settings.TransmitAgent == "efax") { efax = new Efax(); efax.run_efaxd(); } Fax.sendfax(filename); // delete the spool file (~.local/share/gfax/spool/D.*) if (File.Exists(String.Concat(SpoolDirectory, "/", f.Name))) { File.Delete(String.Concat(SpoolDirectory, "/", f.Name)); } //if (!quitAfterSend) { //Gfax gf = new Gfax (filename, args); //} } // delete the spool file that gfax created if it exists if (File.Exists(String.Concat("/var/spool/gfax/", USER, "/", f.Name))) { File.Delete(String.Concat("/var/spool/gfax/", USER, "/", f.Name)); } } else { // We need /var/spool/gfax/<user> to exsist and be 0777 perms //ACCESSPERMS = 0777 if (!Directory.Exists("/var/spool/gfax/" + USER)) { Directory.CreateDirectory("/var/spool/gfax/" + USER); } Mono.Unix.Native.Syscall.chmod("/var/spool/gfax/" + USER, Mono.Unix.Native.FilePermissions.ACCESSPERMS); FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = "/var/spool/gfax/" + USER; watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; // Only watch text files. watcher.Filter = "*"; watcher.Created += new FileSystemEventHandler(TIOnChanged); // Begin watching. watcher.EnableRaisingEvents = true; // Start the fax daemon if efax if (Settings.TransmitAgent == "efax") { efax = new Efax(); efax.run_efaxd(); } Gfax gf = new Gfax(filename, args); } }