예제 #1
0
        private void tsbAddApplication_Click(object sender, EventArgs e)
        {
            var openDialog = new OpenFileDialog();

            openDialog.DefaultExt = "*.exe";
            openDialog.Filter     = "Application EXE Name|*.exe|Application Absolute Path|*.exe";

            if (openDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string applicationName = new FileInfo(openDialog.FileName).Name;
                if (openDialog.FilterIndex == 2)
                {
                    applicationName = openDialog.FileName;
                }

                try
                {
                    _drs.AddApplication(_CurrentProfile, applicationName);
                }
                catch (NvapiException ex)
                {
                    if (ex.Status == Native.NVAPI2.NvAPI_Status.NVAPI_EXECUTABLE_ALREADY_IN_USE || ex.Status == Native.NVAPI2.NvAPI_Status.NVAPI_ERROR)
                    {
                        if (lblApplications.Text.ToUpper().IndexOf(" " + applicationName.ToUpper() + ",") != -1)
                        {
                            MessageBox.Show("This application executable is already assigned to this profile!",
                                            "Error adding Application", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            string profileNames = _scanner.FindProfilesUsingApplication(applicationName);
                            if (profileNames == "")
                            {
                                MessageBox.Show("This application executable might already be assigned to another profile!",
                                                "Error adding Application", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else
                            {
                                MessageBox.Show(
                                    "This application executable is already assigned to the following profiles: " +
                                    profileNames, "Error adding Application", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            RefreshCurrentProfile();
        }
예제 #2
0
        static void Main(string[] args)
        {
            string _CurrentProfile         = "";
            string CURRENTPROFILE_NOX_PATH = "";

            string[]     executeNameList                 = {};
            string       installPath                     = "";
            const string EXTENSIONFILE                   = ".exe";
            const string CURRENTPROFILE_NOX              = "Nox";
            const string amd64InstallPath                = "SOFTWARE\\WOW6432Node\\DuoDianOnline\\SetupInfo";
            const string x86InstallPath                  = "SOFTWARE\\DuoDianOnline\\SetupInfo";
            const float  EPSINON                         = 0.000001F;
            string       CURRENTPROFILE_NOXVMHANDLE      = "\\Bignox\\BigNoxVM\\RT\\NoxVMHandle.exe";
            string       ProgramFiles                    = System.Environment.GetEnvironmentVariable("ProgramFiles");
            string       CURRENTPROFILE_NOXVMHANDLE_PATH = ProgramFiles + CURRENTPROFILE_NOXVMHANDLE;

            _CurrentProfile = CURRENTPROFILE_NOX;

            bool type;

            type = Environment.Is64BitOperatingSystem;

            if (Math.Abs(_import.DriverVersion - 382.64) <= EPSINON)
            {
                //
            }
            if (type)
            {
                installPath = amd64InstallPath;
            }
            else
            {
                installPath = x86InstallPath;
            }

            RegistryKey rsg = null;

            rsg = Registry.LocalMachine.OpenSubKey(installPath);
            if (rsg.ValueCount > 0)
            {
                if (rsg.GetValue("InstallPath") != null)
                {
                    CURRENTPROFILE_NOX_PATH = rsg.GetValue("InstallPath").ToString() + "\\bin\\" + CURRENTPROFILE_NOX + EXTENSIONFILE;
                }
            }

            if (args != null)
            {
                int argsLength = args.Length;
                if (argsLength > 0)
                {
                    executeNameList = new string[argsLength];
                    for (int i = 0; i < argsLength; i++)
                    {
                        executeNameList[i] = args[i];
                    }
                }
                else
                {
                    executeNameList    = new string[2];
                    executeNameList[0] = CURRENTPROFILE_NOX + EXTENSIONFILE;
                    executeNameList[1] = CURRENTPROFILE_NOX_PATH;
                }
            }

            bool existProfileName = false;
            var  profileNames     = _drs.GetProfileNames(ref _CurrentProfile);

            _CurrentProfile = CURRENTPROFILE_NOX;
            if (profileNames.Count > 0)
            {
                foreach (var profileName in profileNames)
                {
                    if (profileName == _CurrentProfile)
                    {
                        existProfileName = true;
                        var applicationList = _drs.GetApplications(profileName);
                        if (executeNameList != null)
                        {
                            int argsLength = executeNameList.Length;
                            for (int i = 0; i < argsLength; i++)
                            {
                                string exeName = executeNameList[i].ToLowerInvariant().Replace("\\", "/");
                                if (!applicationList.Contains(exeName))
                                {
                                    _drs.AddApplication(profileName, executeNameList[i]);
                                }
                            }
                            setProfileSetting(_CurrentProfile);
                            break;
                        }
                    }
                }

                if (!existProfileName)
                {
                    _drs.CreateProfile(_CurrentProfile);
                    if (executeNameList != null)
                    {
                        int argsLength = executeNameList.Length;
                        for (int i = 0; i < argsLength; i++)
                        {
                            _drs.AddApplication(_CurrentProfile, executeNameList[i]);
                        }
                        setProfileSetting(_CurrentProfile);
                    }
                }
            }//end if profileNames.Count
        }