public static int Main(string[] rgArgs) { // Enable visual styles. Ignored on Windows 2000. Needs to be called before // we create any controls! Unfortunately, this alone is not good enough. We // also need to use a manifest, because some ListView and TreeView controls // in native code do not have icons if we just use this method. This is caused // by a bug in XP. Application.EnableVisualStyles(); // Create a semaphore to keep more than one instance of the application // from running at the same time. If the semaphore is signalled, then // this instance can run. Win32.SecurityAttributes sa = new Win32.SecurityAttributes(); IntPtr semaphore = Win32.CreateSemaphore(ref sa, 1, 1, Process.GetCurrentProcess().MainModule.ModuleName); switch (Win32.WaitForSingleObject(semaphore, 0)) { case Win32.WAIT_OBJECT_0: // Using the 'using' gizmo will call Dispose on app, // which in turn will call Dispose for all FdoCache objects, // which will release all of the COM objects it connects to. using (LexTextApp application = new LexTextApp(rgArgs)) { SIL.Utils.ErrorReporter.EmailAddress = "*****@*****.**"; string extensionBaseDir = SIL.FieldWorks.Common.Utils.DirectoryFinder.GetFWDataSubDirectory(@"\Language Explorer\Configuration\Words\Extensions"); string extensionDir = Path.Combine(extensionBaseDir, "Respeller"); if (Directory.Exists(extensionDir)) { try { foreach (string file in Directory.GetFiles(extensionDir)) { File.SetAttributes(file, FileAttributes.Normal); } Directory.Delete(extensionDir, true); } catch { MessageBox.Show(String.Format("Please delete the '{0}' folder and all files in it, in order to run Language Explorer.", extensionDir)); return 1; } } extensionDir = Path.Combine(extensionBaseDir, "DeleteWordforms"); if (Directory.Exists(extensionDir)) { try { foreach (string file in Directory.GetFiles(extensionDir)) { File.SetAttributes(file, FileAttributes.Normal); } Directory.Delete(extensionDir, true); } catch { MessageBox.Show(String.Format("Please delete the '{0}' folder and all files in it, in order to run Language Explorer.", extensionDir)); return 1; } } application.Run(); } int previousCount; Win32.ReleaseSemaphore(semaphore, 1, out previousCount); break; case Win32.WAIT_TIMEOUT: // If the semaphore wait times out then another instance is running. // Try to get a handle to its window and activate it. Then terminate // this process. try { IntPtr hWndMain = ExistingProcess.MainWindowHandle; if (hWndMain != (IntPtr)0) Win32.SetForegroundWindow(hWndMain); } catch { // The other instance does not have a window handle. It is either in // the process of starting up or shutting down. } break; } return 0; }
private static FwXWindow RefreshCacheWindowAndAll(LexTextApp app, string fullProjectFileName) { var manager = app.FwManager; var appArgs = new FwAppArgs(fullProjectFileName); var newAppWindow = (FwXWindow)manager.ReopenProject(manager.Cache.ProjectId.Name, appArgs).ActiveMainWindow; if (IsVernacularSpellingEnabled(newAppWindow.Mediator)) WfiWordformServices.ConformSpellingDictToWordforms(newAppWindow.Cache); //clear out any sort cache files (or whatever else might mess us up) and then refresh newAppWindow.ClearInvalidatedStoredData(); newAppWindow.RefreshDisplay(); return newAppWindow; }
public static int Main(string[] rgArgs) { return(LexTextApp.Main(rgArgs)); }
public static int Main(string[] rgArgs) { // Enable visual styles. Ignored on Windows 2000. Needs to be called before // we create any controls! Unfortunately, this alone is not good enough. We // also need to use a manifest, because some ListView and TreeView controls // in native code do not have icons if we just use this method. This is caused // by a bug in XP. Application.EnableVisualStyles(); // Create a semaphore to keep more than one instance of the application // from running at the same time. If the semaphore is signalled, then // this instance can run. Win32.SecurityAttributes sa = new Win32.SecurityAttributes(); IntPtr semaphore = Win32.CreateSemaphore(ref sa, 1, 1, Process.GetCurrentProcess().MainModule.ModuleName); switch (Win32.WaitForSingleObject(semaphore, 0)) { case Win32.WAIT_OBJECT_0: // Using the 'using' gizmo will call Dispose on app, // which in turn will call Dispose for all FdoCache objects, // which will release all of the COM objects it connects to. using (LexTextApp application = new LexTextApp(rgArgs)) { SIL.Utils.ErrorReporter.EmailAddress = "*****@*****.**"; string extensionBaseDir = SIL.FieldWorks.Common.Utils.DirectoryFinder.GetFWDataSubDirectory(@"\Language Explorer\Configuration\Words\Extensions"); string extensionDir = Path.Combine(extensionBaseDir, "Respeller"); if (Directory.Exists(extensionDir)) { try { foreach (string file in Directory.GetFiles(extensionDir)) { File.SetAttributes(file, FileAttributes.Normal); } Directory.Delete(extensionDir, true); } catch { MessageBox.Show(String.Format("Please delete the '{0}' folder and all files in it, in order to run Language Explorer.", extensionDir)); return(1); } } extensionDir = Path.Combine(extensionBaseDir, "DeleteWordforms"); if (Directory.Exists(extensionDir)) { try { foreach (string file in Directory.GetFiles(extensionDir)) { File.SetAttributes(file, FileAttributes.Normal); } Directory.Delete(extensionDir, true); } catch { MessageBox.Show(String.Format("Please delete the '{0}' folder and all files in it, in order to run Language Explorer.", extensionDir)); return(1); } } application.Run(); } int previousCount; Win32.ReleaseSemaphore(semaphore, 1, out previousCount); break; case Win32.WAIT_TIMEOUT: // If the semaphore wait times out then another instance is running. // Try to get a handle to its window and activate it. Then terminate // this process. try { IntPtr hWndMain = ExistingProcess.MainWindowHandle; if (hWndMain != (IntPtr)0) { Win32.SetForegroundWindow(hWndMain); } } catch { // The other instance does not have a window handle. It is either in // the process of starting up or shutting down. } break; } return(0); }