Esempio n. 1
0
        private void hook_KeyPressed(object sender, KeyboardHookEventArgs e)
        {
            if (e.KeyStroke.Alt == false && e.KeyStroke.Ctrl == false && e.KeyStroke.Shift == false && e.KeyStroke.KeyCode == Keys.Enter)
            {
                if (_frmEdge != null)
                {
                    _frmEdge.SaveSettings();
                    SwitchToThisWindow(_swHandle, false);
                    _frmEdge.Activate();
                }
                else
                    return;

            }
            else if (e.KeyStroke.Alt == true && e.KeyStroke.Ctrl == true && e.KeyStroke.Shift == true && e.KeyStroke.KeyCode == Keys.F)
            {
                hook.KeyPressed -= new KeyboardHookEventHandler(hook_KeyPressed);
                hook.Uninstall();
                hook.Dispose();
                hook = null;
                var dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string lastFileLocation = dirName + "\\Furniture.dll";
                _iSwApp.UnloadAddIn(lastFileLocation); //(@"C:\Program Files\SolidWorks-Russia\MrDoors\Furniture.dll");
            }
        }
Esempio n. 2
0
        public bool ConnectToSW(object thisSw, int cookie)
        {
            // �������� ��� ��������� � xml config
            Furniture.Helpers.SaveLoadSettings.SaveAllProperties();

            bool ret;
            _iSwApp = (ISldWorks)thisSw;
            if (!Properties.Settings.Default.CashModeAvailable)
            {
                Properties.Settings.Default.CashModeOn = false;
                Properties.Settings.Default.Save();
            }
            if (!Properties.Settings.Default.KitchenModeAvailable)
            {
                Properties.Settings.Default.KitchenModeOn = false;
                Properties.Settings.Default.Save();
            }
            _addinId = cookie;
            _iSwApp.SetAddinCallbackInfo(0, this, _addinId);

            if (!CheckSolid())
            {
                string strReg = Interaction.InputBox("������� ��������������� ���:", MyTitle, "", 0, 0);
                if (strReg != "")
                {

                    try
                    {
                        // ������ �����
                        // SaveInRegEdit(strReg);
                        Furniture.Helpers.SaveLoadSettings.AddOrUpdateAppSettings("SerialKey", strReg);

                        Properties.Settings.Default.AppRegCode = strReg;  // ������ �������
                        Properties.Settings.Default.Save();

                    }

                    catch (SecurityException ex)
                    {
                        Logging.Log.Instance.Fatal(ex, ex.Message.ToString() + "ConnectToSW");
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        Logging.Log.Instance.Fatal(ex, ex.Message.ToString() + "ConnectToSW");
                    }
                    finally
                    {
                        Properties.Settings.Default.AppRegCode = strReg;  // ������ �������
                        Properties.Settings.Default.Save();
                    }
                }
            }
            if (CheckSolid())
            {
                var dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                #region �������� ������ ����������� �����
                List<string> filesToDownload = new List<string>();
                filesToDownload.Add("Oracle.ManagedDataAccess.dll");
                filesToDownload.Add("log4net.dll");
                foreach (string file in filesToDownload)
                {
                    if (!File.Exists(Path.Combine(dirName, file)))
                    {
                        //�������..
                        UpdaterFromFtp.DownloadFromFtp(file);
                    }
                }

                #endregion

                #region ���������� ������ ����� ��� ����������
                string newFileLocation;

                string lastFileLocation = dirName + "\\Furniture.dll";
                string updFullName = dirName + "\\update_furniture.exe";
                var ss = new SecureString();
                foreach (var ch in Properties.Settings.Default.AdmUsrPsw)
                {
                    ss.AppendChar(ch);
                }
                var psi = new ProcessStartInfo
                              {
                                  UseShellExecute = false,
                                  Domain = Environment.UserDomainName
                              };
                if (CheckIsSolidUserInAdmin())
                {
                    psi.UserName = Properties.Settings.Default.AdmUsrName;
                    psi.Password = ss;
                }
                if (!File.Exists(updFullName))
                {
                    string updTmpPath;
                    if (DownloadUpdFrn(out updTmpPath))
                    {
                        psi.FileName = updTmpPath;
                        psi.Arguments = Path.GetDirectoryName(updTmpPath) + "\\update_furniture.exe" + "@" +
                                        updFullName;
                        Process.Start(psi);
                    }
                }

                #endregion

                #region ����������

                if (CheckUpdate(out newFileLocation))
                {
                    string arguments = newFileLocation + "@" + lastFileLocation;

                    if (File.Exists(updFullName))
                    {
                        if (!CheckIsSolidUserInAdmin())
                        {
                            psi = new ProcessStartInfo(updFullName, arguments);
                            psi.UseShellExecute = false;
                            psi.Domain = Environment.UserDomainName;
                        }
                        else
                        {
                            psi.FileName = updFullName;
                            psi.Arguments = arguments;
                        }
                        Process.Start(psi);
                        return false;
                    }
                }

                if (Properties.Settings.Default.CheckUpdateLib)
                    UpdatePatch();

                #endregion

                _iCmdMgr = _iSwApp.GetCommandManager(cookie);
                ChangeActiveDoc(false);

                _swEventPtr = (SldWorks)_iSwApp;
                _openDocs = new Hashtable();
                AttachEventHandlers();

                AddPmp();
                _swHandle = (IntPtr)((Frame)_iSwApp.Frame()).GetHWnd();
                WriteLogInfoOnServer();

                ret = true;

                hook = new KeyboardHook();
                hook.AddFilter(Keys.F, true, true, true);
                hook.AddFilter(Keys.Enter, false, false, false);
                hook.KeyPressed += new KeyboardHookEventHandler(hook_KeyPressed);
                hook.Install();
            }
            else
            {
                throw new Exception();
            }
            return ret;
        }