Exemple #1
0
        public formMain(ModuleHandler _module, UtilityHandler _utility, KeyboardHook _hook)
        {
            utility = _utility;
            module  = _module;
            hook    = _hook;

            utility.IsDevUser = (Path.GetFileName(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)) == "Debug") ? true : false;

            SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
            AppDomain.CurrentDomain.FirstChanceException += new EventHandler <FirstChanceExceptionEventArgs>(FirstChance_Handler);
            hook.KeyPressed += new EventHandler <KeyPressedEventArgs>(hook_KeyPressed);

            InitializeComponent();
            startupTimer.Start();
            utility.LogEvent("Program probably started OK");

            // Create NotifyIcon to sit in system tray
            icon.Text             = "Jovo" + ((utility.IsDevUser) ? " Development Enviroment" : "");
            icon.Icon             = (utility.IsDevUser) ? Properties.Resources.Jovo_Logo_TestEnv : Properties.Resources.Jovo_Logo;
            icon.Visible          = true;
            icon.ContextMenuStrip = menu;
            icon.MouseDown       += icon_Click;

            UpdateWorker.WorkerReportsProgress = true;
            UpdateWorker.DoWork             += UpdateWorker_DoWork;
            UpdateWorker.RunWorkerCompleted += UpdateWorker_RunWorkerCompleted;
            UpdateWorker.ProgressChanged    += UpdateWorker_ProgressChanged;
            utility.LogEvent("Module Updater starting...");
            UpdateWorker.RunWorkerAsync(true);

            JovoUpdateWorker.DoWork             += JovoUpdateWorker_DoWork;
            JovoUpdateWorker.RunWorkerCompleted += JovoUpdateWorker_RunWorkerCompleted;
            utility.LogEvent("Jovo Updater Starting...");
            JovoUpdateWorker.RunWorkerAsync();

            ConnectionWorker.WorkerReportsProgress = true;
            ConnectionWorker.DoWork             += ConnectionWorker_DoWork;
            ConnectionWorker.RunWorkerCompleted += ConnectionWorker_RunWorkerCompleted;
        }
Exemple #2
0
 private void doWork_Click(object sender, EventArgs e)
 {
     if (update)
     {
         utility.LogEvent("Notification Clicked");
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
     else
     {
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
 }
Exemple #3
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>

        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ModuleHandler  module  = new ModuleHandler();
            UtilityHandler utility = new UtilityHandler();
            KeyboardHook   hook    = new KeyboardHook();

            utility.ArchiveLog();

            utility.LogEvent("############################ Program starting... ############################", true, true);
            module.GetSetDirectoryStructure(System.Reflection.Assembly.GetEntryAssembly().Location);

            utility.LogEvent("Startup Args received : " + args.Length);

            //foreach (string arg in args)
            //{
            //    utility.LogEvent("Start Argument : " + arg);
            //}

            if (args.Length >= 2)
            {
                //Module_Update_Remote_Path
                string[] temp = args[1].Split('\\');
                temp[temp.Length - 1] = "modules";
                string module_path = String.Join("\\", temp);


                Jovo.Default.Jovo_Updater_Local_Path   = args[0].Trim('"');
                Jovo.Default.Jovo_Update_Remote_Path   = args[1].Trim('"');
                Jovo.Default.Module_Update_Remote_Path = module_path;
                Jovo.Default.Save();
            }

            Application.Run(new formMain(module, utility, hook));
        }
Exemple #4
0
 public bool ExecuteModule(ModuleData data)
 {
     try
     {
         if (data.IsConnected)
         {
             utility.LogEvent("Trying to start module: " + data.Name);
             if (File.Exists(data.Path + "\\" + data.Name + ".exe"))
             {
                 Process.Start(data.Path + "\\" + data.Name + ".exe");
                 utility.LogEvent("... Success", false);
                 return(true);
             }
             utility.LogEvent("... Failed (doesn't exist)", false);
             return(false);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     { return(false); }
 }
Exemple #5
0
        public void GetModuleUpdates(UtilityHandler utility, BackgroundWorker worker, bool OutputResult = true)
        {
            GetModules();
            GetServerModules();

            foreach (ModuleData AvailableModule in ServerModules)
            {
                DirectoryInfo localDir        = new DirectoryInfo(AppModulePath + "\\" + AvailableModule.Name);
                ModuleData    InstalledModule = InstalledModules.Find(m => m == AvailableModule);

                if (!Directory.Exists(AppModulePath + "\\" + AvailableModule.Name))
                {
                    if (OutputResult)
                    {
                        utility.LogEvent("Installing module " + AvailableModule.Name);
                    }

                    worker.ReportProgress(0, new NotificationData()
                    {
                        Title = "Installing Module...", Text = AvailableModule.Name, Timeout = 5000, Method = "Show"
                    });

                    Directory.CreateDirectory(AppModulePath + "\\" + AvailableModule.Name);
                    CopyAll(new DirectoryInfo(AvailableModule.Path), localDir, utility);

                    worker.ReportProgress(0, new NotificationData()
                    {
                        Method = "Hide"
                    });
                }
                else if (AvailableModule > InstalledModule)
                {
                    utility.LogEvent($"Updating {InstalledModule.Name} v{InstalledModule.Version} to {AvailableModule.Version}");
                    worker.ReportProgress(0, new NotificationData()
                    {
                        Title = "Updating Module...", Text = AvailableModule.Name, Timeout = 5000, Method = "Show"
                    });

                    CopyAll(new DirectoryInfo(AvailableModule.Path), localDir, utility);

                    ModuleData newModuleVersion = JsonConvert.DeserializeObject <ModuleData>(File.ReadAllText(AppModulePath + "\\" + InstalledModule.Name + "\\manifest.json"));
                    if (newModuleVersion.IsActive != InstalledModule.IsActive)
                    {
                        newModuleVersion.IsActive = InstalledModule.IsActive;

                        string json = JsonConvert.SerializeObject(newModuleVersion, Formatting.Indented);
                        File.WriteAllText(AppModulePath + "\\" + InstalledModule.Name + "\\manifest.json", json);
                    }

                    worker.ReportProgress(0, new NotificationData()
                    {
                        Method = "Hide"
                    });
                }
            }

            if (ServerModules.Count > 0)
            {
                foreach (ModuleData data in InstalledModules)
                {
                    if (!ServerModules.Contains(data))
                    {
                        Directory.Delete(data.Path, true);
                        utility.LogEvent("Module not found on server (" + data.Name + "), Deleteing local module...");
                    }
                }
            }

            GetModules(OutputResult);
        }
Exemple #6
0
        private void save_Click(object sender, EventArgs e)
        {
            warningPrompted = false;

            Button btn = (Button)sender;

            if (btn.Tag == null)
            {
                foreach (SettingsProperty setting in Jovo.Default.Properties)
                {
                    if (setting.Name.Contains("Module_Name"))
                    {
                        foreach (Control cntrl in pnlSettings.Controls)
                        {
                            if (cntrl.Name == "cbx" + setting.Name)
                            {
                                ComboBox value = (ComboBox)cntrl;
                                Jovo.Default[setting.Name] = value.Text;
                            }
                        }
                    }
                    else
                    {
                        foreach (Control cntrl in pnlSettings.Controls)
                        {
                            if (cntrl.Name == "txt" + setting.Name)
                            {
                                TextBox value = (TextBox)cntrl;
                                Jovo.Default[setting.Name] = value.Text;
                            }
                            else if (cntrl.Name == "cbx" + setting.Name)
                            {
                                ComboBox value = (ComboBox)cntrl;
                                Jovo.Default[setting.Name] = Convert.ToBoolean(value.SelectedItem);
                            }
                        }
                    }
                }
                Jovo.Default.Save();
                ShowMessage("Settings for Jovo were saved successfully!", 1, 152, 117);
                settingsChanged = false;
            }
            else
            {
                List <SettingData> save = new List <SettingData>();
                foreach (SettingData data in module.GetModuleSettings((ModuleData)btn.Tag))
                {
                    foreach (Control cntrl in pnlSettings.Controls)
                    {
                        switch (data.Domain)
                        {
                        case "boolean":
                            if (cntrl.Name == "cbx" + data.Name)
                            {
                                ComboBox value = (ComboBox)cntrl;

                                SettingData set = new SettingData
                                {
                                    Name   = data.Name,
                                    Text   = data.Text,
                                    Domain = data.Domain,
                                    Value  = value.SelectedItem.ToString()
                                };

                                save.Add(set);
                            }
                            break;

                        case "integer":
                            if (cntrl.Name == "num" + data.Name)
                            {
                                NumericUpDown value = (NumericUpDown)cntrl;

                                SettingData set = new SettingData
                                {
                                    Name   = data.Name,
                                    Text   = data.Text,
                                    Domain = data.Domain,
                                    Value  = value.Value.ToString()
                                };

                                save.Add(set);
                            }
                            break;

                        default:
                            if (cntrl.Name == "txt" + data.Name)
                            {
                                TextBox value = (TextBox)cntrl;

                                SettingData set = new SettingData
                                {
                                    Name   = data.Name,
                                    Text   = data.Text,
                                    Domain = data.Domain,
                                    Value  = value.Text
                                };

                                save.Add(set);
                            }
                            break;
                        }
                    }
                }

                if (module.SaveModuleSettings((ModuleData)btn.Tag, save))
                {
                    ShowMessage("Settings for " + ((ModuleData)btn.Tag).Name + " were saved successfully!", 1, 152, 117);
                    settingsChanged = false;
                }
                else
                {
                    utility.LogEvent("Error occured while saving settings (file does not exist)");
                }
            }
        }
Exemple #7
0
        private void UpdateWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if ((bool)e.Result)
            {
                utility.LogEvent("Updater finished - building menu");
            }

            int prev_cat  = 0;
            int first_cat = -1;

            menu.Items.Clear();
            List <ModuleData> SortedList = module.InstalledModules.Where(m => m.IsActive == true && m.CreateMenuItem == true).OrderBy(m => m.Category).ToList();

            foreach (ModuleData data in SortedList)
            {
                if ((prev_cat != data.Category) && (first_cat != -1))
                {
                    sep = new ToolStripSeparator();
                    menu.Items.Add(sep);
                }

                first_cat = (first_cat == -1) ? data.Category : first_cat;

                item      = new ToolStripMenuItem();
                item.Name = data.Name;
                item.Text = data.Text;
                item.Tag  = data;
                if (File.Exists(data.Path + "\\" + data.Icon))
                {
                    var bytes = File.ReadAllBytes(data.Path + "\\" + data.Icon);
                    var ms    = new MemoryStream(bytes);
                    item.Image = Image.FromStream(ms);
                }
                else
                {
                    item.Image = Properties.Resources.settings;
                }

                if (!String.IsNullOrEmpty(data.KeyboardShortcut))
                {
                    item.ShortcutKeys = utility.GetModuleKeyboardShortcut(data.KeyboardShortcut, hook);
                }

                item.Click += menu_Click;
                menu.Items.Add(item);

                prev_cat = data.Category;
            }

            // Create context menu items and add to menu
            sep = new ToolStripSeparator();
            menu.Items.Add(sep);

            item        = new ToolStripMenuItem();
            item.Name   = "tsUpdate";
            item.Text   = "Check For Updates";
            item.Tag    = "update";
            item.Image  = Properties.Resources.refresh;
            item.Click += menu_Click;
            menu.Items.Add(item);

            item        = new ToolStripMenuItem();
            item.Name   = "tsChangelog";
            item.Text   = "View Changelog";
            item.Tag    = "changelog";
            item.Image  = Properties.Resources.changelog;
            item.Click += menu_Click;
            menu.Items.Add(item);

            item        = new ToolStripMenuItem();
            item.Name   = "tsModules";
            item.Text   = "Modules";
            item.Tag    = "modules";
            item.Image  = Properties.Resources.module;
            item.Click += menu_Click;
            menu.Items.Add(item);

            item        = new ToolStripMenuItem();
            item.Name   = "tsSettings";
            item.Text   = "Settings";
            item.Tag    = "settings";
            item.Image  = Properties.Resources.settings;
            item.Click += menu_Click;
            menu.Items.Add(item);

            item        = new ToolStripMenuItem();
            item.Name   = "tsExit";
            item.Text   = "Exit";
            item.Tag    = "exit";
            item.Image  = Properties.Resources.close;
            item.Click += menu_Click;
            menu.Items.Add(item);

            if (FirstStartup)
            {
                utility.LogEvent($"Startup finished in {startupTimer.Elapsed.TotalSeconds.ToString()} seconds");
                utility.LogEvent($"Total memory usage: {Process.GetCurrentProcess().PrivateMemorySize64 / (1024 * 1024)} MB allocated ({Environment.WorkingSet / (1024 * 1024)} MB mapped)");
                FirstStartup = false;

                utility.LogEvent("Connection BackgroundWorker Started...");
                ConnectionWorker.RunWorkerAsync();
            }
        }