static void Windows() { //Console.InputEncoding = System.Text.Encoding.UTF8; using (var fs = WinConsole.GetStandardIn()) using (var reader = new StreamReader(fs, Console.InputEncoding)) { var box = new TerminalBox(reader, Console.Out); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { // replace this with manual call to enable mouse/vt support on various platforms // TODO shutodown and tracking 'previous' modes for windows var winbox = new WinConsole(); winbox.Initialize(); box.ResizeEvent += (s, e) => { // remove scroll on win Console.Clear(); Console.SetBufferSize(Console.WindowWidth, Console.WindowHeight); }; box.EnableMouse(true); Start(box); } } }
protected override void OnStartup(StartupEventArgs e) { // Class "ReflectionContext" exists from .NET 4.5 onwards. if (Type.GetType("System.Reflection.ReflectionContext", false) == null) { MessageBox.Show(string.Format("{0} requirers .NET Framework 4.5 or newer. In order to run {0} please update your .NET installation.", App.Title), App.Title, MessageBoxButton.OK, MessageBoxImage.Stop); Environment.Exit(0); } args = Environment.GetCommandLineArgs(); HasConsole = WinConsole.Initialize(TestArg("-console")); if (TestArg("-dbg_wait")) { MessageBox.Show("Waiting for debugger. (press ok when attached)"); } if (TestArg("-dbg_log")) { AppDomain.CurrentDomain.FirstChanceException += FirstChanceExceptionHandler; } App.exePath = Assembly.GetExecutingAssembly().Location; App.appPath = Path.GetDirectoryName(exePath); //App.exeName = Path.GetFileName(exePath); //FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(exePath); //App.Title = fvi.FileDescription; // PrivateWin10 - Setup //App.exeName = fvi.OriginalFilename; // PrivateSetup.exe base.OnStartup(e); }
public ConnectPage() { InitializeComponent(); #if DEBUG MockButton.Visibility = Visibility.Visible; WinConsole.Initialize(); #endif }
protected override void ConfigureModuleCatalog() { base.ConfigureModuleCatalog(); var catalog = (ModuleCatalog)this.ModuleCatalog; catalog.AddModule(typeof(Module1Module)); WinConsole.Initialize(); }
public ConnectPage() { InitializeComponent(); #if DEBUG WinConsole.Initialize(); #else MockButton.Visibility = Visibility.Hidden; #endif }
public MainViewModel() { WinConsole.Initialize(); ExitCommand = new Command(Exit); ConsoleCommand = new Command(p => WinConsole.Visible = !WinConsole.Visible); AddCommand = new Command(Add); DeleteCommand = new Command(Delete) { CanExecuteFunction = p => CanDelete }; EditCommand = new Command(Edit) { CanExecuteFunction = p => CanEdit }; AboutCommand = new Command(ShowAboutDialog); LoadCommand = new Command(Load); SaveCommand = new Command(Save); ClearFilterCommand = new Command(() => FilterText = ""); CalcCommand = new Command(Calculate); OpenFileCommand = new Command { CanExecuteFunction = p => true, ExecuteFunction = p => OpenFile() }; People = new ObservableCollection <Person>(); Config = new Configurator(); PeopleView = CollectionViewSource.GetDefaultView(People); PeopleView.Filter = obj => { if (FilterText.IsEmpty()) { return(true); } var p = obj as Person; return(p != null && p.FullName.IndexOf(FilterText, StringComparison.CurrentCultureIgnoreCase) >= 0); }; Initialize(); }
public MainViewModel() { ExitCommand = new Command(() => Application.Current.Shutdown()); SelectItemCommand = new Command(SelectItem); if (DesignerProperties.GetIsInDesignMode(new DependencyObject())) { Root = new DirItem(); } else { WinConsole.Initialize(); Root = FileTreeLoader.Instance.Load(@"U:\Data"); } }
public static void Main(string[] args) { App.args = args; HasConsole = WinConsole.Initialize(TestArg("-console")); if (TestArg("-dbg_wait")) { MessageBox.Show("Waiting for debugger. (press ok when attached)"); } if (TestArg("-dbg_log")) { AppDomain.CurrentDomain.FirstChanceException += FirstChanceExceptionHandler; } StartModes startMode = StartModes.Normal; // Normal GUI Mode if (TestArg("-svc")) { startMode = StartModes.Service; } else if (TestArg("-engine")) { startMode = StartModes.Engine; } Log = new AppLog(Key); AppLog.ExceptionLogID = (long)EventIDs.Exception; AppLog.ExceptionCategory = (short)EventFlags.DebugEvents; if (startMode == StartModes.Normal) { Log.EnableLogging(); Log.LoadLog(); } // When running as worker we need the windows event log else if (!Log.UsingEventLog()) { Log.SetupEventLog(Key); } // load current version exePath = Process.GetCurrentProcess().MainModule.FileName; //System.Reflection.Assembly.GetExecutingAssembly().Location; FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(exePath); Version = fvi.FileMajorPart + "." + fvi.FileMinorPart; if (fvi.FileBuildPart != 0) { Version += "." + fvi.FileBuildPart; } if (fvi.FilePrivatePart != 0) { Version += (char)('a' + (fvi.FilePrivatePart - 1)); } appPath = Path.GetDirectoryName(exePath); Translate.Load(); dataPath = appPath + @"\Data"; if (File.Exists(GetINIPath())) // if an ini exists in the app path, its considdered to be a portable run { isPortable = true; AppLog.Debug("Portable Mode"); } else { string progData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); if (progData == null) { progData = @"C:\ProgramData"; } dataPath = progData + "\\" + Key; } AppLog.Debug("Config Directory: {0}", dataPath); // execute commandline commands if (ExecuteCommands()) { return; } if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } if (AdminFunc.IsAdministrator()) { FileOps.SetAnyDirSec(dataPath); } App.LogInfo("PrivateWin10 Process Started, Mode {0}.", startMode.ToString()); Session = Process.GetCurrentProcess().SessionId; // setup custom assembly resolution for x86/x64 synamic compatybility AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveHandler; // is the process starting as a service/worker? if (startMode != StartModes.Normal) { engine = new Priv10Engine(); if (startMode == StartModes.Service) { using (Priv10Service svc = new Priv10Service()) ServiceBase.Run(svc); } else { engine.Run(); } return; } Thread.CurrentThread.Name = "Gui"; client = new Priv10Client(); // Encure wie have the required privilegs //if (!AdminFunc.IsDebugging()) { AppLog.Debug("Trying to connect to Engine..."); int conRes = client.Connect(1000); if (conRes == 0) { if (!AdminFunc.IsAdministrator()) { AppLog.Debug("Trying to obtain Administrative proivilegs..."); if (AdminFunc.SkipUacRun(App.Key, App.args)) { return; } AppLog.Debug("Trying to start with 'runas'..."); // Restart program and run as admin string arguments = "\"" + string.Join("\" \"", args) + "\""; ProcessStartInfo startInfo = new ProcessStartInfo(exePath, arguments); startInfo.UseShellExecute = true; startInfo.Verb = "runas"; try { Process.Start(startInfo); return; // we restarted as admin } catch { //MessageBox.Show(Translate.fmt("msg_admin_rights", mName), mName); //return; // no point in cintinuing without admin rights or an already running engine } } else if (Priv10Service.IsInstalled()) { AppLog.Debug("Trying to start service..."); if (Priv10Service.Startup()) { AppLog.Debug("Trying to connect to service..."); if (client.Connect() != 0) { AppLog.Debug("Connected to service..."); } else { AppLog.Debug("Failed to connect to service..."); } } else { AppLog.Debug("Failed to start service..."); } } } else if (conRes == -1) { MessageBox.Show(Translate.fmt("msg_dupliate_session", Title), Title); return; // no point in cintinuing without admin rights or an already running engine } } // tweaks = new TweakManager(); // if we couldn't connect to the engine start it and connect if (!client.IsConnected() && AdminFunc.IsAdministrator()) { AppLog.Debug("Starting Engine Thread..."); engine = new Priv10Engine(); engine.Start(); AppLog.Debug("... engine started."); client.Connect(); } var app = new App(); app.InitializeComponent(); InitLicense(); MainWnd = new MainWindow(); TrayIcon = new TrayIcon(); TrayIcon.Action += TrayAction; TrayIcon.Visible = (GetConfigInt("Startup", "Tray", 0) != 0) || App.TestArg("-autorun"); if (!App.TestArg("-autorun") || !TrayIcon.Visible) { MainWnd.Show(); } app.Run(); TrayIcon.DestroyNotifyicon(); client.Close(); tweaks.Store(); if (engine != null) { engine.Stop(); } }
public static void Main(string[] args) { App.args = args; HasConsole = WinConsole.Initialize(TestArg("-console")); if (TestArg("-dbg_wait")) { MessageBox.Show("Waiting for debugger. (press ok when attached)"); } if (TestArg("-dbg_log")) { AppDomain.CurrentDomain.FirstChanceException += FirstChanceExceptionHandler; } StartModes startMode = StartModes.Normal; // Normal GUI Mode if (TestArg("-svc")) { startMode = StartModes.Service; } else if (TestArg("-engine")) { startMode = StartModes.Engine; } Log = new AppLog(Key); AppLog.ExceptionLogID = (long)Priv10Logger.EventIDs.Exception; AppLog.ExceptionCategory = (short)Priv10Logger.EventFlags.DebugEvents; // When running as worker we need the windows event log if (!Log.UsingEventLog()) { Log.SetupEventLog(Key); } // load current version exePath = Process.GetCurrentProcess().MainModule.FileName; //System.Reflection.Assembly.GetExecutingAssembly().Location; //*FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(exePath); //Version = fvi.FileMajorPart + "." + fvi.FileMinorPart; //if (fvi.FileBuildPart != 0) // Version += "." + fvi.FileBuildPart; //if (fvi.FilePrivatePart != 0) // Version += (char)('a' + (fvi.FilePrivatePart - 1)); appPath = Path.GetDirectoryName(exePath); dataPath = appPath + @"\Data"; if (File.Exists(GetINIPath())) // if an ini exists in the app path, its considdered to be a portable run { isPortable = true; AppLog.Debug("Portable Mode"); } else { string progData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); if (progData == null) { progData = @"C:\ProgramData"; } dataPath = progData + "\\" + Key; } AppLog.Debug("Config Directory: {0}", dataPath); if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } if (AdminFunc.IsAdministrator()) { FileOps.SetAnyDirSec(dataPath); } Priv10Logger.LogInfo("PrivateWin10 Service Process Started, Mode {0}.", startMode.ToString()); // setup custom assembly resolution for x86/x64 synamic compatybility AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveHandler; // is the process starting as a service/worker? if (startMode != StartModes.Normal) { engine = new Priv10Engine(); if (startMode == StartModes.Service) { using (Priv10Service svc = new Priv10Service()) ServiceBase.Run(svc); } else { engine.Run(); } return; } }
static void Main(string[] args) { Program.args = args; mConsole = WinConsole.Initialize(TestArg("-console")); if (TestArg("-help") || TestArg("/?")) { ShowHelp(); return; } if (TestArg("-dbg_wait")) { MessageBox.Show("Waiting for debugger. (press ok when attached)"); } Console.WriteLine("Starting..."); appPath = Path.GetDirectoryName(Application.ExecutablePath); System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); mVersion = fvi.FileMajorPart + "." + fvi.FileMinorPart; if (fvi.FileBuildPart != 0) { mVersion += (char)('a' + (fvi.FileBuildPart - 1)); } Translate.Load(); AppLog Log = new AppLog(); AppLog.Line("{0}, Version v{1} by David Xanatos", mName, mVersion); AppLog.Line("This Tool is Open Source under the GNU General Public License, Version 3\r\n"); ipc = new PipeIPC("wumgr_pipe"); var client = ipc.Connect(100); if (client != null) { AppLog.Line("Application is already running."); client.Send("show"); string ret = client.Read(1000); if (!ret.Equals("ok", StringComparison.CurrentCultureIgnoreCase)) { MessageBox.Show(Translate.fmt("msg_running")); } return; } if (!MiscFunc.IsAdministrator() && !MiscFunc.IsDebugging()) { Console.WriteLine("Trying to get admin privileges..."); if (SkipUacRun()) { Application.Exit(); return; } if (!MiscFunc.IsRunningAsUwp()) { Console.WriteLine("Trying to start with 'runas'..."); // Restart program and run as admin var exeName = Process.GetCurrentProcess().MainModule.FileName; string arguments = "\"" + string.Join("\" \"", args) + "\""; ProcessStartInfo startInfo = new ProcessStartInfo(exeName, arguments); startInfo.UseShellExecute = true; startInfo.Verb = "runas"; try { Process.Start(startInfo); Application.Exit(); return; } catch { //MessageBox.Show(Translate.fmt("msg_admin_req", mName), mName); AppLog.Line("Administrator privileges are required in order to install updates."); } } } wrkPath = appPath; if (!FileOps.TestWrite(GetINIPath())) { Console.WriteLine("Can't write to default working directory."); string downloadFolder = KnownFolders.GetPath(KnownFolder.Downloads); if (downloadFolder == null) { downloadFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads"; } wrkPath = downloadFolder + @"\WuMgr"; try { if (!Directory.Exists(wrkPath)) { Directory.CreateDirectory(wrkPath); } } catch { MessageBox.Show(Translate.fmt("msg_ro_wrk_dir", wrkPath), mName); } } /*switch(FileOps.TestFileAdminSec(mINIPath)) * { * case 0: * AppLog.Line("Warning wumgr.ini was writable by non administrative users, it was renamed to wumgr.ini.old and replaced with a empty one.\r\n"); * if (!FileOps.MoveFile(mINIPath, mINIPath + ".old", true)) * return; * goto case 2; * case 2: // file missing, create * FileOps.SetFileAdminSec(mINIPath); * break; * case 1: // every thign's fine ini file is only writable by admins * break; * }*/ AppLog.Line("Working Directory: {0}", wrkPath); Agent = new WuAgent(); ExecOnStart(); Agent.Init(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new WuMgr()); Agent.UnInit(); ExecOnClose(); }
public static void Main(string[] args) { App.args = args; mConsole = WinConsole.Initialize(TestArg("-console") || TestArg("-console-debug")); if (TestArg("-help") || TestArg("/?")) { ShowHelp(); return; } else if (TestArg("-dbg_wait")) { MessageBox.Show("Waiting for debugger. (press ok when attached)"); } Thread.CurrentThread.Name = "Main"; Console.WriteLine("Starting..."); AppLog Log = new AppLog(); exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(exePath); mVersion = fvi.FileMajorPart + "." + fvi.FileMinorPart; if (fvi.FileBuildPart != 0) { mVersion += (char)('a' + (fvi.FileBuildPart - 1)); } appPath = Path.GetDirectoryName(exePath); mSession = Process.GetCurrentProcess().SessionId; Translate.Load(); svc = new Service(mSvcName); if (TestArg("-engine")) { engine = new Engine(); engine.Run(); return; } else if (TestArg("-svc")) { if (TestArg("-install")) { Console.WriteLine("Installing service..."); svc.Install(TestArg("-start")); Console.WriteLine("... done"); } else if (TestArg("-remove")) { Console.WriteLine("Removing service..."); svc.Uninstall(); Console.WriteLine("... done"); } else { engine = new Engine(); ServiceBase.Run(svc); } return; } tweaks = new Tweaks(); client = new PipeClient(); if (!AdminFunc.IsDebugging()) { Console.WriteLine("Trying to connect to Engine..."); if (!client.Connect(1000)) { if (!AdminFunc.IsAdministrator()) { Console.WriteLine("Trying to obtain Administrative proivilegs..."); if (AdminFunc.SkipUacRun(mName, App.args)) { return; } Console.WriteLine("Trying to start with 'runas'..."); // Restart program and run as admin var exeName = Process.GetCurrentProcess().MainModule.FileName; string arguments = "\"" + string.Join("\" \"", args) + "\""; ProcessStartInfo startInfo = new ProcessStartInfo(exeName, arguments); startInfo.UseShellExecute = true; startInfo.Verb = "runas"; try { Process.Start(startInfo); return; // we restarted as admin } catch { MessageBox.Show(Translate.fmt("msg_admin_rights", mName), mName); return; // no point in cintinuing without admin rights or an already running engine } } else if (svc.IsInstalled()) { Console.WriteLine("Trying to start service..."); if (svc.Startup()) { Console.WriteLine("Trying to connect to service..."); if (client.Connect()) { Console.WriteLine("Connected to service..."); } else { Console.WriteLine("Failed to connect to service..."); } } else { Console.WriteLine("Failed to start service..."); } } } } // if we couldn't connect to the engine start it and connect if (!client.IsConnected() && AdminFunc.IsAdministrator()) { Console.WriteLine("Starting Engine Thread..."); engine = new Engine(); engine.Start(); Console.WriteLine("... engine started."); client.Connect(); } // ToDo: use a more direct communication when running in one process itf = client; cb = client; /*if (TestArg("-console-debug")) * { * Console.WriteLine("Private WinTen reporting for duty, sir!"); * Console.WriteLine(""); * * for (bool running = true; running;) * { * String Line = Console.ReadLine(); * if (Line.Length == 0) * continue; * * String Command = TextHelpers.GetLeft(ref Line).ToLower(); * * if (Command == "quit" || Command == "exit") * running = false; * * if (Command == "test") * { * } * else * { * Console.WriteLine("Unknown Command, sir!"); * continue; * } * Console.WriteLine("Yes, sir!"); * } * * return; * }*/ Console.WriteLine("Preparing GUI..."); var app = new App(); app.InitializeComponent(); InitLicense(); mTray = new TrayIcon(); mTray.Action += TrayAction; mTray.Visible = GetConfigInt("Startup", "Tray", 0) != 0; mMainWnd = new MainWindow(); if (!App.TestArg("-autorun") || !mTray.Visible) { mMainWnd.Show(); } app.Run(); mTray.DestroyNotifyicon(); client.Close(); if (engine != null) { engine.Stop(); } }
public static void Main(string[] args) { App.args = args; HasConsole = WinConsole.Initialize(TestArg("-console")); if (TestArg("-dbg_wait")) { MessageBox.Show("Waiting for debugger. (press ok when attached)"); } if (TestArg("-dbg_log")) { AppDomain.CurrentDomain.FirstChanceException += FirstChanceExceptionHandler; } Log = new AppLog(Key); AppLog.ExceptionLogID = (long)Priv10Logger.EventIDs.Exception; AppLog.ExceptionCategory = (short)Priv10Logger.EventFlags.DebugEvents; Log.EnableLogging(); Log.LoadLog(); // load current version exePath = Process.GetCurrentProcess().MainModule.FileName; //System.Reflection.Assembly.GetExecutingAssembly().Location; FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(exePath); Version = fvi.FileMajorPart + "." + fvi.FileMinorPart; if (fvi.FileBuildPart != 0) { Version += "." + fvi.FileBuildPart; } if (fvi.FilePrivatePart != 0) { Version += (char)('a' + (fvi.FilePrivatePart - 1)); } appPath = Path.GetDirectoryName(exePath); Translate.Load(); dataPath = appPath + @"\Data"; if (File.Exists(GetINIPath())) // if an ini exists in the app path, its considdered to be a portable run { isPortable = true; AppLog.Debug("Portable Mode"); } else { string progData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); if (progData == null) { progData = @"C:\ProgramData"; } dataPath = progData + "\\" + Key; } AppLog.Debug("Config Directory: {0}", dataPath); // execute commandline commands if (ExecuteCommands()) { return; } if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } if (AdminFunc.IsAdministrator()) { FileOps.SetAnyDirSec(dataPath); } // setup custom assembly resolution for x86/x64 synamic compatybility //AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveHandler; Thread.CurrentThread.Name = "Gui"; client = new Priv10Client(); if (!AdminFunc.IsAdministrator()) { if (AdminFunc.SkipUacRun(App.Key, App.args)) { return; } if (App.GetConfigInt("Startup", "ShowSetup", 1) == 1) { AppLog.Debug("Trying to restart as admin..."); if (Restart(true)) { return; } } } AppLog.Debug("Trying to connect to engine..."); int conRes = client.Connect(1000); if (conRes == 0) { if (Priv10Service.IsProperlyInstalled()) { if (!AdminFunc.IsAdministrator()) { MessageBox.Show(Translate.fmt("msg_admin_rights_svc", Title, SvcName), Title); Restart(true); return; } AppLog.Debug("Trying to start service..."); if (!Priv10Service.Startup()) { AppLog.Debug("Failed to start service..."); } } else if (App.GetConfigInt("Firewall", "Enabled", 0) != 0) { AppLog.Debug("Trying to start engine process..."); StartEngine(); } AppLog.Debug("Trying to connect to engine..."); if (client.Connect() != 0) { AppLog.Debug("Connected to engine..."); } else { AppLog.Debug("Failed to connect to engine..."); } } tweaks = new TweakManager(); presets = new PresetManager(); var app = new App(); app.InitializeComponent(); InitLicense(); MainWnd = new MainWindow(); TrayIcon = new TrayIcon(); TrayIcon.Visible = (GetConfigInt("Startup", "Tray", 1) != 0) || App.TestArg("-autorun"); if (!App.TestArg("-autorun") || !TrayIcon.Visible) { MainWnd.Show(); } app.Run(); TrayIcon.DestroyNotifyicon(); presets.Store(); tweaks.Store(); if (EngineProc != null) { StopEngine(); } else { client.Close(); } }
static Context() { Config.ContextStarted = true; ContextManager.SetWriteLine(WriteLine); var stopwatch = new Stopwatch(); stopwatch.Start(); // this should go somewhere on startup // also, verify any other platform specs if (!BitConverter.IsLittleEndian) { throw new NotSupportedException(); } if (Config.ShowConsole) { WinConsole.Initialize(); c_writeLineAction = WinConsole.WriteLine; } else { Action <string> defaultWriteLine = Console.WriteLine; //Trace.WriteLine; c_writeLineAction = (s, args) => defaultWriteLine(string.Format(s, args)); } c_registeredProperties = new Dictionary <PropertyName, IPropertyState>(); c_registeredPropertiesList = new List <IPropertyState>(); c_sources = new Dictionary <PointCloudTileSource, FileHandlerBase>(); c_loadedPaths = new Dictionary <string, FileHandlerBase>(StringComparer.OrdinalIgnoreCase); c_queue = new ProcessingQueue(); c_backgroundWorker = new ManagedBackgroundWorker(); c_backgroundWorker.WorkerReportsProgress = true; c_backgroundWorker.WorkerSupportsCancellation = true; c_backgroundWorker.DoWork += OnBackgroundDoWork; c_backgroundWorker.ProgressChanged += OnBackgroundProgressChanged; c_backgroundWorker.RunWorkerCompleted += OnBackgroundRunWorkerCompleted; Config.Write(); #warning EXTENSION SEARCH IS AUTOMATIC (for testing) System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(ExtensionManager).TypeHandle); //if (Config.EnableExtensionDiscovery) // RegisterExtensions(); if (Config.EnableFactoryDiscovery) { ExtensionManager.ProcessLoadedTypesInitialize("Factories", typeof(IFactory)); } if (Config.EnablePropertyDiscovery) { ExtensionManager.ProcessLoadedTypesInitialize("Properties", typeof(IPropertyContainer)); } long startupElapsed = stopwatch.ElapsedMilliseconds; stopwatch.Restart(); if (Config.EnableInstrumentation) { SystemInfo.Write(); } stopwatch.Stop(); WriteLine("[Startup]"); WriteLine(" Discover : {0}ms", startupElapsed); WriteLine(" Instrument : {0}ms", stopwatch.ElapsedMilliseconds); WriteLine(" Total : {0}ms", stopwatch.ElapsedMilliseconds + startupElapsed); WriteLine(); }
static void Main(string[] args) { Program.args = args; mConsole = WinConsole.Initialize(TestArg("-console")); if (TestArg("-help") || TestArg("/?")) { ShowHelp(); return; } if (TestArg("-dbg_wait")) { MessageBox.Show("Waiting for debugger. (press ok when attached)"); } Console.WriteLine("Starting..."); System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); mVersion = fvi.FileMajorPart + "." + fvi.FileMinorPart; if (fvi.FileBuildPart != 0) { mVersion += (char)('a' + (fvi.FileBuildPart - 1)); } AppLog Log = new AppLog(); AppLog.Line("{0}, Version v{1} by David Xanatos", mName, mVersion); AppLog.Line("This Tool is Open Source under the GNU General Public License, Version 3\r\n"); appPath = Path.GetDirectoryName(Application.ExecutablePath); ipc = new PipeIPC("wumgr_pipe"); var client = ipc.Connect(100); if (client != null) { AppLog.Line("Application is already running."); client.Send("show"); string ret = client.Read(1000); if (!ret.Equals("ok", StringComparison.CurrentCultureIgnoreCase)) { MessageBox.Show(MiscFunc.fmt("Application is already running.")); } return; } if (IsAdministrator() == false) { Console.WriteLine("Trying to get admin privilegs..."); if (!SkipUacRun()) { Console.WriteLine("Trying to start with 'runas'..."); // Restart program and run as admin var exeName = Process.GetCurrentProcess().MainModule.FileName; string arguments = "\"" + string.Join("\" \"", args) + "\""; ProcessStartInfo startInfo = new ProcessStartInfo(exeName, arguments); startInfo.UseShellExecute = true; startInfo.Verb = "runas"; try { Process.Start(startInfo); } catch { MessageBox.Show(MiscFunc.fmt("The {0} requirers Administrator privilegs.\r\nPlease restart the application as Administrator.\r\n\r\nYou can use the option Start->'Bypass User Account Control' to solve this issue for future startsups.", mName), mName); } } Application.Exit(); return; } mINIPath = appPath + @"\wumgr.ini"; /*switch(FileOps.TestFileAdminSec(mINIPath)) * { * case 0: * AppLog.Line("Warning wumgr.ini was writable by non administrative users, it was renamed to wumgr.ini.old and replaced with a empty one.\r\n"); * if (!FileOps.MoveFile(mINIPath, mINIPath + ".old", true)) * return; * goto case 2; * case 2: // file missing, create * FileOps.SetFileAdminSec(mINIPath); * break; * case 1: // every thign's fine ini file is only writable by admins * break; * }*/ Agent = new WuAgent(); ExecOnStart(); Agent.Init(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new WuMgr()); Agent.UnInit(); ExecOnClose(); }