Example #1
0
        public bool UndoTweak(Tweak tweak)
        {
            tweak.State  = TweakList.Tweak.States.Unsellected;
            tweak.Status = false;

            if (!tweak.IsAvailable())
            {
                return(false);
            }

            bool success;

            if (AdminFunc.IsAdministrator() || tweak.usrLevel)
            {
                success = TweakTools.UndoTweak(tweak);
            }
            else
            {
                success = App.client.UndoTweak(tweak);
            }
            TweakChanged?.Invoke(this, new TweakEventArgs()
            {
                tweak = tweak
            });
            return(success);
        }
Example #2
0
 public ActionResult Login(AdminLoginViewModel adminLoginViewModel)
 {
     if (ModelState.IsValid)
     {
         AdminFunc adminFunc = new AdminFunc();
         var       _response = adminFunc.Verify(adminLoginViewModel.Accounts, adminLoginViewModel.Password);
         if (_response.Code == 1)
         {
             var _user = adminFunc.Find(adminLoginViewModel.Accounts);
             Session.Add("AdminID", _user.AdministratorID);
             Session.Add("Accounts", _user.Accounts);
             adminFunc.UpdateAdminLoginInfo(_user.AdministratorID, DateTime.Now, "127.0.0.1");
             return(RedirectToAction("Index", "Admin"));
         }
         else if (_response.Code == 3)
         {
             ModelState.AddModelError("Accounts Or Password", _response.Message);
         }
         else
         {
             ModelState.AddModelError("", _response.Message);
         }
     }
     return(View(adminLoginViewModel));
 }
Example #3
0
        private void menuExit_Click(object Sender, EventArgs e)
        {
            //notifyIcon1.Visible = false;

            // Close the form, which closes the application.
            //Application.Exit();

            if (Priv10Service.IsInstalled() && AdminFunc.IsAdministrator())
            {
                MessageBoxResult res = MessageBox.Show(Translate.fmt("msg_stop_svc"), App.Title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                switch (res)
                {
                case MessageBoxResult.Yes:
                    if (!Priv10Service.Terminate())
                    {
                        MessageBox.Show(Translate.fmt("msg_stop_svc_err"), App.Title, MessageBoxButton.OK, MessageBoxImage.Stop);
                    }
                    break;

                case MessageBoxResult.Cancel:
                    return;
                }
            }
            Application.Current.Shutdown();
        }
Example #4
0
        private void toggle_Checked(object sender, RoutedEventArgs e)
        {
            if (!AdminFunc.IsAdministrator())
            {
                ReqSU?.Invoke(this, e);
                OnStatusChanged(null, null);
                return;
            }

            /*if ((sender as ToggleSwitch).IsChecked == null)
             *  (sender as ToggleSwitch).IsChecked = true;*/

            bool state = (bool)(sender as ToggleSwitch).IsChecked;

            foreach (Tweak tweak in myGroup.Tweaks)
            {
                if (!tweak.IsAvailable())
                {
                    continue;
                }

                if (state && (tweak.Sellected == null ? !tweak.Optional : (bool)tweak.Sellected))
                {
                    tweak.Apply();
                }
                else if (!state)
                {
                    tweak.Undo();
                }
            }
        }
Example #5
0
        public bool ApplyTweak(Tweak tweak, bool?byUser = null)
        {
            if (byUser != null)
            {
                tweak.State = byUser == true ? TweakList.Tweak.States.Sellected : TweakList.Tweak.States.SelGroupe;
            }
            tweak.Status = true;

            if (!tweak.IsAvailable())
            {
                return(false);
            }

            bool success;

            if (AdminFunc.IsAdministrator() || tweak.usrLevel)
            {
                success = TweakTools.ApplyTweak(tweak);
            }
            else
            {
                success = App.client.ApplyTweak(tweak);
            }

            TweakChanged?.Invoke(this, new TweakEventArgs()
            {
                tweak = tweak
            });
            return(success);
        }
Example #6
0
        static void TrayAction(object sender, TrayIcon.TrayEventArgs args)
        {
            if (MainWnd == null || !MainWnd.FullyLoaded)
            {
                return;
            }

            switch (args.Action)
            {
            case TrayIcon.Actions.ToggleWindow:
            {
                if (MainWnd.IsVisible)
                {
                    MainWnd.Hide();
                }
                else
                {
                    MainWnd.Show();
                }
                break;
            }

            case TrayIcon.Actions.ToggleNotify:
            {
                if (MainWnd.notificationWnd.IsVisible)
                {
                    MainWnd.notificationWnd.HideWnd();
                }
                else if (!MainWnd.notificationWnd.IsEmpty())
                {
                    MainWnd.notificationWnd.ShowWnd();
                }
                break;
            }

            case TrayIcon.Actions.CloseApplication:
            {
                if (Priv10Service.IsInstalled() && AdminFunc.IsAdministrator())
                {
                    MessageBoxResult res = MessageBox.Show(Translate.fmt("msg_stop_svc"), App.Title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                    switch (res)
                    {
                    case MessageBoxResult.Yes:
                        if (!Priv10Service.Terminate())
                        {
                            MessageBox.Show(Translate.fmt("msg_stop_svc_err"), App.Title, MessageBoxButton.OK, MessageBoxImage.Stop);
                        }
                        break;

                    case MessageBoxResult.Cancel:
                        return;
                    }
                }
                Application.Current.Shutdown();
                break;
            }
            }
        }
Example #7
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            UpdateSysMenu(); // Install system menu

            if (AdminFunc.IsAdministrator() && App.GetConfigInt("Startup", "ShowSetup", 1) == 1 && !Priv10Service.IsInstalled())
            {
                ShowSetup();
            }
        }
Example #8
0
        public bool TestTweak(Tweak tweak, bool fixChanged = false)
        {
            if (!tweak.IsAvailable())
            {
                return(false);
            }

            bool status;

            if (AdminFunc.IsAdministrator() || tweak.usrLevel || !App.client.IsConnected())
            {
                status = TweakEngine.TestTweak(tweak);
            }
            else
            {
                status = App.client.TestTweak(tweak);
            }

            if (tweak.Status != status)
            {
                tweak.Status         = status;
                tweak.LastChangeTime = DateTime.Now;

                Dictionary <string, string> Params = new Dictionary <string, string>();
                Params.Add("Name", tweak.Name);
                Params.Add("Group", tweak.Group);
                Params.Add("Category", tweak.Category);

                if (tweak.Status == false && tweak.State != Tweak.States.Unsellected)
                {
                    if (fixChanged == true && tweak.FixFailed == false)
                    {
                        ApplyTweak(tweak);

                        if (TestTweak(tweak, false) != true)
                        {
                            tweak.FixFailed = true;
                            App.LogError(App.EventIDs.TweakError, Params, App.EventFlags.Notifications, Translate.fmt("msg_tweak_stuck", tweak.Name, tweak.Group));
                        }
                        else
                        {
                            tweak.FixedCount++;
                            App.LogInfo(App.EventIDs.TweakFixed, Params, App.EventFlags.Notifications, Translate.fmt("msg_tweak_fixed", tweak.Name, tweak.Group));
                        }
                    }
                    else
                    {
                        App.LogWarning(App.EventIDs.TweakChanged, Params, App.EventFlags.Notifications, Translate.fmt("msg_tweak_un_done", tweak.Name, tweak.Group));
                    }
                }
            }
            return(status);
        }
        public OverviewPage()
        {
            InitializeComponent();

            string running = Translate.fmt("lbl_run_as", Translate.fmt(AdminFunc.IsAdministrator() ? "str_admin" : "str_user"));

            if (App.svc.IsInstalled())
            {
                running += Translate.fmt("lbl_run_svc");
            }
            lblRunning.Content = running;

            lblFirewallInfo.Content = Translate.fmt((App.GetConfigInt("Firewall", "Enabled", 0) != 0) ? "str_enabled" : "str_disabled");
        }
Example #10
0
        private void BtnOK_Click(object sender, RoutedEventArgs e)
        {
            bool Restart = false;

            if (chkAutoStart.IsChecked == true)
            {
                App.SetConfig("Startup", "Tray", true);
                App.TrayIcon.Visible = true;

                App.AutoStart(true);
                if (chkService.IsChecked == true)
                {
                    Priv10Service.Install();
                    App.Log.SetupEventLog(App.Key);
                    Restart = true;
                }
            }
            if (chkNoUAC.IsChecked == true)
            {
                AdminFunc.SkipUacEnable(App.Key, true);
            }

            if (chkUseFW.IsChecked == true)
            {
                App.SetConfig("Firewall", "Enabled", 1);

                FirewallManager.FilteringModes Mode = FirewallManager.FilteringModes.WhiteList;
                App.SetConfig("Firewall", "Mode", Mode.ToString());
                App.client.SetFilteringMode(Mode);

                FirewallMonitor.Auditing audit = FirewallMonitor.Auditing.All;
                App.SetConfig("Firewall", "AuditPol", audit.ToString());
                App.client.SetAuditPolicy(audit);

                App.SetConfig("Firewall", "NotifyConnections", chkNotifyFW.IsChecked == true ? 1 : 0);

                if (!App.client.IsConnected())
                {
                    App.StartEngine();
                    App.client.Connect();
                }
            }

            App.SetConfig("Startup", "ShowSetup", 0);
            if (Restart)
            {
                App.Restart();
            }
            this.DialogResult = true;
        }
Example #11
0
        private void UpdateSysMenu()
        {
            /// Get the Handle for the Forms System Menu
            IntPtr systemMenuHandle = GetSystemMenu(this.Handle, false);

            /// Create our new System Menu items just before the Close menu item
            InsertMenu(systemMenuHandle, 5, MF_BYPOSITION | MF_SEPARATOR, 0, string.Empty); // <-- Add a menu seperator
            InsertMenu(systemMenuHandle, 6, MF_BYPOSITION | (AdminFunc.IsAdministrator() ? MF_DISABLED : MF_ENABLED), SysMenu_Setup, Translate.fmt("menu_setup"));
            InsertMenu(systemMenuHandle, 7, MF_BYPOSITION | (AdminFunc.IsAdministrator() ? MF_DISABLED : MF_ENABLED), SysMenu_Uninstall, Translate.fmt("menu_uninstall"));

            // Attach our WndProc handler to this Window
            HwndSource source = HwndSource.FromHwnd(this.Handle);

            source.AddHook(new HwndSourceHook(WndProc));
        }
Example #12
0
        private void chkNoUAC_Click(object sender, RoutedEventArgs e)
        {
            if (bHold)
            {
                return;
            }

            if (!AdminFunc.IsAdministrator())
            {
                if (MessageBox.Show(Translate.fmt("msg_admin_prompt", App.Title), App.Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    App.Restart(true);
                }
                return;
            }

            AdminFunc.SkipUacEnable(App.Key, chkNoUAC.IsChecked == true);
        }
Example #13
0
        public SetupWnd()
        {
            InitializeComponent();

            this.Title = Translate.fmt("wnd_setup", App.Title);

            this.lblStartup.Text      = Translate.fmt("lbl_startup_options");
            this.chkAutoStart.Content = Translate.fmt("chk_autorun");
            this.chkService.Content   = Translate.fmt("chk_instal_svc");
            this.chkNoUAC.Content     = Translate.fmt("chk_no_uac");

            this.lblFirewall.Text    = Translate.fmt("lbl_firewall_options");
            this.chkUseFW.Content    = Translate.fmt("chk_manage_fw");
            this.chkNotifyFW.Content = Translate.fmt("chk_show_notify");

            chkNoUAC.IsChecked    = AdminFunc.IsSkipUac(App.Key);
            chkNotifyFW.IsChecked = App.GetConfigInt("Firewall", "NotifyConnections", 1) != 0;
        }
Example #14
0
        private void toggle_Click(object sender, RoutedEventArgs e)
        {
            if (!myTweak.usrLevel && !AdminFunc.IsAdministrator())
            {
                ReqSU?.Invoke(this, e);
                OnStatusChanged(null, null);
                return;
            }

            if ((bool)toggle.IsChecked)
            {
                myTweak.Apply((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Control) == 0);
            }
            else
            {
                myTweak.Undo((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Control) == 0);
            }
        }
Example #15
0
        private void chkService_Click(object sender, RoutedEventArgs e)
        {
            if (bHold)
            {
                return;
            }

            if (!AdminFunc.IsAdministrator())
            {
                if (MessageBox.Show(Translate.fmt("msg_admin_prompt", App.Title), App.Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    App.Restart(true);
                }
                return;
            }

            if (chkService.IsChecked == true)
            {
                if (App.EngineProc != null)
                {
                    App.StopEngine();
                }

                Priv10Service.Install(true);
                App.Log.SetupEventLog(App.Key);
                App.client.Connect();
            }
            else
            {
                App.client.Close();

                Priv10Service.Terminate();
                Priv10Service.Uninstall();

                if (App.EngineProc == null && App.GetConfigInt("Firewall", "Enabled", 0) != 0)
                {
                    App.StartEngine();
                    App.client.Connect();
                }
            }


            App.MainWnd.UpdateEnabled();
        }
        public void Refresh()
        {
            bHold = true;

            chkTray.IsChecked      = App.GetConfigInt("Startup", "Tray") != 0;
            chkAutoStart.IsChecked = App.IsAutoStart();
            chkService.IsChecked   = App.svc.IsInstalled();
            chkNoUAC.IsChecked     = AdminFunc.IsSkipUac(App.mName);

            chkUseFW.IsChecked = App.GetConfigInt("Firewall", "Enabled", 0) != 0;

            if (App.client.IsConnected())
            {
                var mode = App.itf.GetFilteringMode();

                radWhitelist.IsChecked = mode == Firewall.FilteringModes.WhiteList;
                radBlacklist.IsChecked = mode == Firewall.FilteringModes.BlackList;
                radDisabled.IsChecked  = mode == Firewall.FilteringModes.NoFiltering;

                var pol = App.itf.GetAuditPol();
                switch (pol)
                {
                case Firewall.Auditing.All: cmbAudit.SelectedItem = lblAuditAll; break;

                case Firewall.Auditing.Blocked: cmbAudit.SelectedItem = lblAuditBlock; break;

                default: cmbAudit.SelectedItem = lblAuditAll; break;
                }
            }
            else
            {
                chkUseFW.IsEnabled = false;

                radWhitelist.IsEnabled = false;
                radBlacklist.IsEnabled = false;
                radDisabled.IsEnabled  = false;
                cmbAudit.IsEnabled     = false;
            }

            chkNotifyFW.IsEnabled = chkUseFW.IsChecked == true;
            chkNotifyFW.IsChecked = App.GetConfigInt("Firewall", "NotifyBlocked", 1) != 0;

            bHold = false;
        }
        private void BtnOK_Click(object sender, RoutedEventArgs e)
        {
            bool Restart = false;

            if (chkAutoStart.IsChecked == true)
            {
                App.SetConfig("Startup", "Tray", true);
                App.mTray.Visible = true;

                App.AutoStart(true);
                if (chkService.IsChecked == true)
                {
                    App.svc.Install();
                    Restart = true;
                }
            }
            if (chkNoUAC.IsChecked == true)
            {
                AdminFunc.SkipUacEnable(App.mName, true);
            }

            if (chkUseFW.IsChecked == true)
            {
                App.SetConfig("Firewall", "Enabled", 1);

                Firewall.FilteringModes Mode = Firewall.FilteringModes.WhiteList;
                App.SetConfig("Firewall", "Mode", Mode.ToString());
                App.itf.SetFilteringMode(Mode);

                Firewall.Auditing audit = Firewall.Auditing.All;
                App.SetConfig("Firewall", "AuditPol", audit.ToString());
                App.itf.SetAuditPol(audit);

                App.SetConfig("Firewall", "NotifyBlocked", chkNotifyFW.IsChecked == true ? 1 : 0);
            }

            App.SetConfig("Startup", "ShowSetup", 0);
            if (Restart)
            {
                App.Restart();
            }
            this.DialogResult = true;
        }
Example #18
0
        private void chkService_Click(object sender, RoutedEventArgs e)
        {
            if (bHold)
            {
                return;
            }

            if (!AdminFunc.IsAdministrator())
            {
                if (MessageBox.Show(Translate.fmt("msg_admin_prompt", App.mName), App.mName, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    App.Restart(true);
                }
                return;
            }

            App.client.Close();
            if (chkService.IsChecked == true)
            {
                if (App.engine != null)
                {
                    App.engine.Stop();

                    App.engine = null;
                }

                App.svc.Install(true);
                App.Log.SetupEventLog(App.mAppName);
            }
            else
            {
                App.svc.Uninstall();

                if (App.engine == null)
                {
                    App.engine = new Engine();

                    App.engine.Start();
                }
            }
            App.client.Connect();
        }
Example #19
0
        public void OnShow()
        {
            string running = Translate.fmt("lbl_run_as", Translate.fmt(AdminFunc.IsAdministrator() ? "str_admin" : "str_user"));

            if (Priv10Service.IsInstalled())
            {
                running += Translate.fmt("lbl_run_svc");
            }
            lblRunning.Content = running;

            lblFirewallInfo.Content = Translate.fmt((App.GetConfigInt("Firewall", "Enabled", 0) != 0) ? "str_enabled" : "str_disabled");
            // filterming mode
            // current profile
            lblRuleGuardInfo.Content = Translate.fmt(App.client.IsFirewallGuard() ? "str_enabled" : "str_disabled");
            // changed rules

            lblTweakGuardInfo.Content = Translate.fmt(App.GetConfigInt("TweakGuard", "AutoCheck", 1) != 0 ? "str_enabled" : "str_disabled");
            // mode
            // changed tweaks
        }
Example #20
0
        public bool UndoTweak(Tweak tweak)
        {
            if (!tweak.IsAvailable())
            {
                return(false);
            }

            bool success;

            if (AdminFunc.IsAdministrator() || tweak.usrLevel)
            {
                success = TweakEngine.UndoTweak(tweak);
            }
            else
            {
                success = App.client.UndoTweak(tweak);
            }
            //StatusChanged?.Invoke(this, new EventArgs());
            return(success);
        }
Example #21
0
 public static bool HasAdministrator()
 {
     return(AdminFunc.IsAdministrator() || App.client.IsConnected());
 }
Example #22
0
        public bool TestTweak(Tweak tweak, bool fixChanged = false)
        {
            if (!tweak.IsAvailable())
            {
                return(false);
            }

            bool status;

            if (AdminFunc.IsAdministrator() || tweak.usrLevel || !App.client.IsConnected())
            {
                status = TweakTools.TestTweak(tweak);
            }
            else
            {
                status = App.client.TestTweak(tweak);
            }

            if (tweak.Status != status)
            {
                tweak.Status         = status;
                tweak.LastChangeTime = DateTime.Now;

                if (tweak.Status == false && tweak.State != Tweak.States.Unsellected)
                {
                    Dictionary <string, string> Params = new Dictionary <string, string>();
                    Params.Add("Name", tweak.Name);
                    Params.Add("Group", tweak.Group);
                    Params.Add("Category", tweak.Category);

                    TweakEventArgs.State state = TweakEventArgs.State.eChanged;

                    if (fixChanged == true && tweak.FixFailed == false)
                    {
                        ApplyTweak(tweak);

                        if (TestTweak(tweak, false) != true)
                        {
                            tweak.FixFailed = true;
                            Priv10Logger.LogError(Priv10Logger.EventIDs.TweakError, Params, Priv10Logger.EventFlags.Notifications, Translate.fmt("msg_tweak_stuck", tweak.Name, tweak.Group));
                        }
                        else
                        {
                            state = TweakEventArgs.State.eRestored;
                            tweak.FixedCount++;
                            Priv10Logger.LogInfo(Priv10Logger.EventIDs.TweakFixed, Params, Priv10Logger.EventFlags.Notifications, Translate.fmt("msg_tweak_fixed", tweak.Name, tweak.Group));
                        }
                    }
                    else
                    {
                        Priv10Logger.LogWarning(Priv10Logger.EventIDs.TweakChanged, Params, Priv10Logger.EventFlags.AppLogEntries, Translate.fmt("msg_tweak_un_done", tweak.Name, tweak.Group));
                    }

                    if (state == TweakEventArgs.State.eChanged)
                    {
                        TweakChanged?.Invoke(this, new TweakEventArgs()
                        {
                            tweak = tweak, state = state
                        });
                    }
                }
            }
            return(status);
        }
Example #23
0
        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();
            }
        }
Example #24
0
        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();
            }
        }
Example #25
0
        static bool ExecuteCommands()
        {
            if (TestArg("-help") || TestArg("/?"))
            {
                string   Message = "Available command line options\r\n";
                string[] Help    =
                {
                    "Available Console Commands:",
                    "========================================",
                    "",
                    "-state\t\t\tShow instalation state",
                    "-uninstall\t\tUninstall PrivateWinTen",
                    "",
                    "-svc_install\t\tInstall priv10 service (invokes -log_install)",
                    "-svc_remove\t\tRemove priv10 service",
                    "",
                    "-log_install\t\tInstall PrivateWin10 Custom Event Log",
                    "-log_remove\t\tRemove PrivateWin10 Custom Event Log",
                    "",
                    "-console\t\tShow console with debug output",
                    "-help\t\t\tShow this help message"
                };
                if (!HasConsole)
                {
                    MessageBox.Show(Message + string.Join("\r\n", Help));
                }
                else
                {
                    Console.WriteLine(Message);
                    for (int j = 0; j < Help.Length; j++)
                    {
                        Console.WriteLine(" " + Help[j]);
                    }
                }
                return(true);
            }


            bool bDone = false;

            if (TestArg("-svc_install"))
            {
                AppLog.Debug("Installing Service...");
                svc.Install(TestArg("-svc_start"));
                bDone = true;
            }

            if (TestArg("-log_install") || TestArg("-svc_install")) // service needs the event log
            {
                AppLog.Debug("Setting up Event Log...");
                Log.SetupEventLog(mAppName);
                bDone = true;
            }

            if (TestArg("-uninstall"))
            {
                AppLog.Debug("Uninstalling PrivateWinTen");
                bDone = true;
            }

            if (TestArg("-svc_remove") || (svc.IsInstalled() && TestArg("-uninstall")))
            {
                AppLog.Debug("Removing Service...");
                svc.Uninstall();
                bDone = true;
            }

            if (TestArg("-log_remove") || (Log.UsingEventLog() && TestArg("-uninstall")))
            {
                AppLog.Debug("Removing Event Log...");
                Log.RemoveEventLog(mAppName);
                bDone = true;
            }

            if (TestArg("-uninstall") && AdminFunc.IsSkipUac(mName))
            {
                AppLog.Debug("Removing UAC Bypass...");
                AdminFunc.SkipUacEnable(mName, false);
                bDone = true;
            }

            if (TestArg("-uninstall") && App.IsAutoStart())
            {
                AppLog.Debug("Removing Autostart...");
                App.AutoStart(false);
                bDone = true;
            }

            if (bDone)
            {
                AppLog.Debug("done");
            }


            if (TestArg("-state"))
            {
                Console.WriteLine();
                Console.WriteLine("Instalation State:");
                Console.WriteLine("========================="); // 25
                Console.Write("Auto Start:\t");
                Console.WriteLine(App.IsAutoStart());
                Console.Write("UAC Bypass:\t");
                Console.WriteLine(AdminFunc.IsSkipUac(mName));
                Console.Write("Event Log:\t");
                Console.WriteLine(Log.UsingEventLog());
                Console.Write("Service:\t");
                Console.WriteLine(svc.IsInstalled());
                Console.WriteLine();
            }

            if (TestArg("-wait"))
            {
                Console.WriteLine();
                for (int i = 10; i >= 0; i--)
                {
                    Console.Write("\r{0}%   ", i);
                    Thread.Sleep(1000);
                }
            }

            return(bDone);
        }
Example #26
0
        public void Refresh()
        {
            bHold = true;

            chkTray.IsChecked      = App.GetConfigInt("Startup", "Tray", 1) != 0;
            chkAutoStart.IsChecked = App.IsAutoStart();
            chkService.IsChecked   = Priv10Service.IsInstalled();
            chkNoUAC.IsChecked     = AdminFunc.IsSkipUac(App.Key);

            chkTweakCheck.IsChecked = App.GetConfigInt("TweakGuard", "AutoCheck", 1) != 0;
            chkTweakFix.IsEnabled   = chkTweakCheck.IsChecked == true;
            chkTweakFix.IsChecked   = App.GetConfigInt("TweakGuard", "AutoFix", 0) != 0;

            chkUseFW.IsChecked = App.GetConfigInt("Firewall", "Enabled", 0) != 0;

            if (App.client.IsConnected())
            {
                var mode = App.client.GetFilteringMode();

                radWhitelist.IsChecked = mode == FirewallManager.FilteringModes.WhiteList;
                radBlacklist.IsChecked = mode == FirewallManager.FilteringModes.BlackList;
                radDisabled.IsChecked  = mode == FirewallManager.FilteringModes.NoFiltering;

                var pol = App.client.GetAuditPolicy();
                switch (pol)
                {
                case FirewallMonitor.Auditing.All: cmbAudit.SelectedItem = lblAuditAll; break;

                case FirewallMonitor.Auditing.Blocked: cmbAudit.SelectedItem = lblAuditBlock; break;

                default: cmbAudit.SelectedItem = lblAuditNone; break;
                }

                chkGuardFW.IsEnabled = chkUseFW.IsChecked == true;
                chkGuardFW.IsChecked = App.client.IsFirewallGuard();

                chkEnableDNS.IsChecked = App.GetConfigInt("DnsProxy", "Enabled", 0) != 0;
            }
            else
            {
                chkUseFW.IsEnabled = false;

                radWhitelist.IsEnabled = false;
                radBlacklist.IsEnabled = false;
                radDisabled.IsEnabled  = false;
                cmbAudit.IsEnabled     = false;

                chkGuardFW.IsEnabled = false;

                chkEnableDNS.IsEnabled = false;
            }

            var fix_mode = App.GetConfigInt("Firewall", "GuardMode", 0);

            radFix.IsChecked     = fix_mode == (int)FirewallGuard.Mode.Fix;
            radDisable.IsChecked = fix_mode == (int)FirewallGuard.Mode.Disable;
            radAlert.IsChecked   = fix_mode == (int)FirewallGuard.Mode.Alert;

            radFix.IsEnabled = radDisable.IsEnabled = radAlert.IsEnabled = (chkGuardFW.IsChecked != false && chkGuardFW.IsEnabled);


            chkNotifyFW.IsEnabled = chkUseFW.IsChecked == true;
            chkNotifyFW.IsChecked = App.GetConfigInt("Firewall", "NotifyConnections", 1) != 0;

            chkDnsInspector.IsChecked = App.GetConfigInt("DnsInspector", "Enabled", 0) != 0;

            chkReverseDNS.IsChecked = App.GetConfigInt("DnsInspector", "UseReverseDNS", 0) != 0;

            // DNS
            chkLocalDNS.IsChecked = App.GetConfigInt("DnsProxy", "SetLocal", 0) != 0;
            string UpstreamDNS = App.GetConfig("DNSProxy", "UpstreamDNS", "8.8.8.8");

            if (!WpfFunc.CmbSelect(cmbRootDNS, UpstreamDNS))
            {
                cmbRootDNS.Text = UpstreamDNS;
            }
            CheckDNS();

            //this.btnBackup.IsEnabled = this.btnRestore.IsEnabled = !App.isPortable;

            bHold = false;
        }
Example #27
0
        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;
            }
        }
Example #28
0
        static bool ExecuteCommands()
        {
            if (TestArg("-help") || TestArg("/?"))
            {
                string   Message = "Available command line options\r\n";
                string[] Help    =
                {
                    "Available Console Commands:",
                    "========================================",
                    "",
                    "-state\t\t\tShow instalation state",
                    "-uninstall\t\tUninstall Private Win10",
                    "-shutdown\t\tClose Private Win10 instances",
                    "-restart\t\tRestart Win10 and reload settings",
                    "",
                    "-svc_install\t\tInstall priv10 service (invokes -log_install)",
                    "-svc_remove\t\tRemove priv10 service",
                    "",
                    "-log_install\t\tInstall PrivateWin10 Custom Event Log",
                    "-log_remove\t\tRemove PrivateWin10 Custom Event Log",
                    "",
                    "-restore_dns\t\tRestore original DNS Configuration",
                    "",
                    "-console\t\tShow console with debug output",
                    "-help\t\t\tShow this help message"
                };
                if (!HasConsole)
                {
                    MessageBox.Show(Message + string.Join("\r\n", Help));
                }
                else
                {
                    Console.WriteLine(Message);
                    for (int j = 0; j < Help.Length; j++)
                    {
                        Console.WriteLine(" " + Help[j]);
                    }
                }
                return(true);
            }


            bool bDone = false;

            if (TestArg("-uninstall"))
            {
                AppLog.Debug("Uninstalling Private Win10");
                bDone = true;
            }

            if (TestArg("-svc_remove") || (Priv10Service.IsInstalled() && TestArg("-uninstall")))
            {
                AppLog.Debug("Removing Service...");
                Priv10Service.Uninstall();
                bDone = true;
            }

            if (TestArg("-shutdown") || TestArg("-restart") || TestArg("-restore") || TestArg("-uninstall"))
            {
                AppLog.Debug("Closing instances...");
                if (Priv10Service.IsInstalled())
                {
                    Priv10Service.Terminate();
                }

                Thread.Sleep(500);

                foreach (var proc in Process.GetProcessesByName(App.Key))
                {
                    if (proc.Id == ProcFunc.CurID)
                    {
                        continue;
                    }
                    proc.Kill();
                }

                bDone = true;
            }

            if (TestArg("-restore"))
            {
                string zipPath = GetArg("-restore");

                try
                {
                    if (zipPath == null || !File.Exists(zipPath))
                    {
                        throw new Exception("Data backup zip not specifyed or invalid path");
                    }

                    Console.WriteLine("Restoring settings from {0}", zipPath);

                    string extractPath = App.dataPath;

                    // Normalizes the path.
                    extractPath = Path.GetFullPath(extractPath);

                    // Ensures that the last character on the extraction path
                    // is the directory separator char.
                    // Without this, a malicious zip file could try to traverse outside of the expected
                    // extraction path.
                    if (!extractPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
                    {
                        extractPath += Path.DirectorySeparatorChar;
                    }

                    // create data directory
                    if (!Directory.Exists(dataPath))
                    {
                        Directory.CreateDirectory(dataPath);
                    }

                    // ensure its writable by non administrators
                    FileOps.SetAnyDirSec(dataPath);

                    // Extract the backuped files
                    using (ZipArchive archive = ZipFile.OpenRead(zipPath))
                    {
                        foreach (ZipArchiveEntry entry in archive.Entries)
                        {
                            // Gets the full path to ensure that relative segments are removed.
                            string destinationPath = Path.GetFullPath(Path.Combine(extractPath, entry.FullName));

                            // Ordinal match is safest, case-sensitive volumes can be mounted within volumes that
                            // are case-insensitive.
                            if (!destinationPath.StartsWith(extractPath, StringComparison.Ordinal))
                            {
                                continue;
                            }

                            Console.WriteLine("Restored file {0}", entry.FullName);
                            if (File.Exists(destinationPath))
                            {
                                FileOps.DeleteFile(destinationPath);
                            }
                            else if (!Directory.Exists(Path.GetDirectoryName(destinationPath)))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));
                            }

                            entry.ExtractToFile(destinationPath);
                        }
                    }
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.Message);
                    MessageBox.Show(Translate.fmt("msg_restore_error", err.Message), App.Title, MessageBoxButton.OK, MessageBoxImage.Stop);
                }

                bDone = true;
            }

            if (TestArg("-restart") || TestArg("-restore"))
            {
                Thread.Sleep(500);

                AppLog.Debug("Starting instances...");
                if (Priv10Service.IsInstalled())
                {
                    Priv10Service.Startup();
                }

                Thread.Sleep(500);

                ProcessStartInfo startInfo = new ProcessStartInfo(App.exePath);
                startInfo.UseShellExecute = true;
                startInfo.Verb            = "runas";
                Process.Start(startInfo);

                bDone = true;
            }

            if (TestArg("-log_remove") || (Log.UsingEventLog() && TestArg("-uninstall")))
            {
                AppLog.Debug("Removing Event Log...");
                Log.RemoveEventLog(Key);
                bDone = true;
            }

            if (TestArg("-svc_install"))
            {
                AppLog.Debug("Installing Service...");
                Priv10Service.Install(TestArg("-svc_start"));
                bDone = true;
            }

            if (TestArg("-log_install") || TestArg("-svc_install")) // service needs the event log
            {
                AppLog.Debug("Setting up Event Log...");
                Log.SetupEventLog(Key);
                bDone = true;
            }

            if (TestArg("-restore_dns") || (DnsConfigurator.IsAnyLocalDNS() && TestArg("-uninstall")))
            {
                AppLog.Debug("Restoring DNS Config...");
                DnsConfigurator.RestoreDNS();
                bDone = true;
            }

            if (TestArg("-uninstall") && AdminFunc.IsSkipUac(App.Key))
            {
                AppLog.Debug("Removing UAC Bypass...");
                AdminFunc.SkipUacEnable(App.Key, false);
                bDone = true;
            }

            if (TestArg("-uninstall") && App.IsAutoStart())
            {
                AppLog.Debug("Removing Autostart...");
                App.AutoStart(false);
                bDone = true;
            }

            if (bDone)
            {
                AppLog.Debug("done");
            }


            if (TestArg("-state"))
            {
                Console.WriteLine();
                Console.WriteLine("Instalation State:");
                Console.WriteLine("========================="); // 25
                Console.Write("Auto Start:\t");
                Console.WriteLine(App.IsAutoStart());
                Console.Write("UAC Bypass:\t");
                Console.WriteLine(AdminFunc.IsSkipUac(App.Key));
                Console.Write("Service:\t");
                Console.WriteLine(Priv10Service.IsInstalled());
                Console.Write("Event Log:\t");
                Console.WriteLine(Log.UsingEventLog());
                Console.Write("Local DNS:\t");
                Console.WriteLine(DnsConfigurator.IsAnyLocalDNS());
                Console.WriteLine();
                bDone = true;
            }

            if (TestArg("-wait"))
            {
                Console.WriteLine();
                for (int i = 10; i >= 0; i--)
                {
                    Console.Write("\r{0}%   ", i);
                    Thread.Sleep(1000);
                }
            }

            return(bDone);
        }
Example #29
0
        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();
            }
        }
Example #30
0
 public static bool HasAdministrator()
 {
     return(AdminFunc.IsAdministrator() || (App.engine == null && App.client.IsConnected()));
 }