Beispiel #1
0
        /// <summary>
        /// 复制文件到系统文件夹
        /// </summary>
        public static void CopySysWOW64(string nsrsbh, string fjh, string drive)
        {
            string    InitSettingFilePath = AppDomain.CurrentDomain.BaseDirectory + "Init";
            MyIniFile ini = new MyIniFile(InitSettingFilePath);

            string systemPath = string.Empty;
            //判断当前系统是否是64位系统
            var bit = GetOSBit();

            if (bit == 64)
            {
                systemPath = Environment.ExpandEnvironmentVariables("%SYSTEMROOT%") + @"\SysWOW64\";
            }
            else
            {
                systemPath = Environment.ExpandEnvironmentVariables("%SYSTEMROOT%") + @"\System32\";
            }
            var filePath = drive + @"SystemFile\";

            if (!Directory.Exists(systemPath))
            {
                return;
            }
            //判断目标路径中是否还有AisinoCSP文件夹,禁止重复复制
            var configValue = ini.IniReadValue("CopyFile", "SystemFile");

            if (Directory.Exists(systemPath + @"\AisinoCSP\") && configValue == "1")
            {
                return;
            }

            CopyFolder(nsrsbh, fjh, filePath, systemPath);
            ini.IniWriteValue("CopyFile", "SystemFile", "1");
        }
Beispiel #2
0
        /// <summary>
        /// 初始化数据库
        /// </summary>
        /// <returns></returns>
        public bool InitializeDataBase()
        {
            var    result     = true;
            var    dbFileName = ConfigHelper.GetAppSettingValue("DbFileName");
            string filePath   = AppDomain.CurrentDomain.BaseDirectory + dbFileName;

            GlobalInfo.DbPath = filePath;
            ConfigHelper.SetConnection("DataModelContainerEntities", filePath);

            var isDBNewCreated = false;

            if (!File.Exists(filePath))
            {
                string path = filePath.Substring(0, filePath.LastIndexOf("\\"));
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                if (!File.Exists(filePath))
                {
                    isDBNewCreated = true;
                    System.Data.SQLite.SQLiteConnection.CreateFile(filePath);
                }

                try
                {
                    //读取配置信息,看数据库是否已经加密;如果没加密,则给数据库设置密码
                    var fileName    = AppDomain.CurrentDomain.BaseDirectory + @"\Init.ini";
                    var myIni       = new MyIniFile(fileName);
                    var isEncrypted = myIni.IniReadValue("InitializeInfo", "DbIsEncrypted");
                    //对已存在数据库,但没经过加密的(isEncrypted == "");及新建的数据库进行加密
                    if (string.IsNullOrEmpty(isEncrypted) || isDBNewCreated)
                    {
                        System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection("Data Source=" + filePath);
                        con.Open();
                        con.ChangePassword(PRO_ReceiptsInvMgr.Resources.Common.DbPwd);
                        myIni.IniWriteValue("InitializeInfo", "DbIsEncrypted", "True");//标示已经加密
                    }
                }
                catch (Exception ex)
                {
                    Logging.Log4NetHelper.Error(this, Message.DBEncryptFail + ex.Message + ex.InnerException + System.Environment.NewLine + ex.StackTrace);
                }

                try
                {
                    ExecSqlList(new List <string> {
                        ConfigHelper.GetAppSettingValue("InitializeScriptName")
                    });
                }
                catch (Exception ex)
                {
                    result = false;
                    Logging.Log4NetHelper.Error(this, Message.CreateDataBase + ex.Message + ex.InnerException + System.Environment.NewLine + ex.StackTrace);
                }
            }

            return(result);
        }
Beispiel #3
0
 private void OpenUpdateProcess(string updateFilePath)
 {
     try
     {
         string    updateResultPath = AppDomain.CurrentDomain.BaseDirectory + "Update.ini";
         MyIniFile ini = new MyIniFile(updateResultPath);
         ini.IniWriteValue("Common", "UpdateFile", updateFilePath);
         ini.IniWriteValue("UpdateResult", updateFilePath, "0");
         Process.Start(AppDomain.CurrentDomain.BaseDirectory + "\\PRO_ReceiptsInvMgr.UpdateApp.exe", "\"" + updateFilePath + "\"");
         CloseClient();
         System.Windows.Application.Current.Shutdown();
     }
     catch (Exception ex)
     {
         Logging.Log4NetHelper.Error(typeof(MainWindow), Message.ExitError + ex.Message + System.Environment.NewLine + ex.StackTrace);
     }
 }
Beispiel #4
0
        /// <summary>
        /// 复制开票软件文件夹
        /// </summary>
        public static void CopyKP(string nsrsbh, string fjh, string drive)
        {
            string    InitSettingFilePath = AppDomain.CurrentDomain.BaseDirectory + "Init";
            MyIniFile ini = new MyIniFile(InitSettingFilePath);

            var filePath = drive + @"\fwkpBase\";
            //获取系统盘符
            var systemPath = string.Format(@"{0}\fwkp\", drive);

            //目标路径中包含该纳税人,禁止重复复制
            if (Directory.Exists(systemPath))
            {
                var configValue = ini.IniReadValue("CopyFile", nsrsbh + "." + fjh);
                if (Directory.Exists(systemPath + nsrsbh + "." + fjh) && configValue == "1")
                {
                    return;
                }
            }
            ini.IniWriteValue("CopyFile", nsrsbh + "." + fjh, "0");

            CopyFolder(nsrsbh, fjh, filePath, systemPath);

            ini.IniWriteValue("CopyFile", nsrsbh + "." + fjh, "1");
        }
        public void DownloadManual()
        {
            ManualResponse manualResponse;
            string         strRequest = new JavaScriptSerializer().Serialize(new { SCVERSION = "" });
            bool           result     = false;
            string         errorMsg   = string.Empty;

            var fileName      = AppDomain.CurrentDomain.BaseDirectory + @"\Init.ini";
            var myIni         = new MyIniFile(fileName);
            var manualVersion = myIni.IniReadValue("InitializeInfo", "ManualVersion");

            if (string.IsNullOrEmpty(manualVersion))
            {
                manualVersion = "1.0.1";
                myIni.IniWriteValue("InitializeInfo", "ManualVersion", manualVersion);
            }

            var response = WSInterface.GetResponse(strRequest, InterfaceType.ManualDownload, ref result, out errorMsg);

            if (result)
            {
                try
                {
                    manualResponse = new JsonSerializer().Deserialize <ManualResponse>(new JsonTextReader(new StringReader(response)));
                    if (manualResponse == null)
                    {
                        return;
                    }
                    if (!string.IsNullOrEmpty(manualResponse.SCWJURL))
                    {
                        if (GetClientVersionToDouble(manualVersion) >= GetClientVersionToDouble(manualResponse.SCVERSION))
                        {
                            return;
                        }

                        bool           isFinish       = false;
                        DownloadHelper downLoadHelper = new DownloadHelper(manualResponse.SCWJURL, AppDomain.CurrentDomain.BaseDirectory);
                        downLoadHelper.GetTotalSize();

                        string localFileName = AppDomain.CurrentDomain.BaseDirectory + downLoadHelper.FileName;

                        if (!File.Exists(localFileName) || (File.Exists(localFileName) && new FileInfo(localFileName).Length < downLoadHelper.TotalSize))
                        {
                            string downLoadStep = ConfigHelper.GetAppSettingValue("DownloadStep");

                            downLoadHelper.Step = !string.IsNullOrEmpty(downLoadStep) ? Convert.ToInt32(downLoadStep) : 102400;
                            while (!downLoadHelper.IsFinished)
                            {
                                downLoadHelper.Download();
                            }
                            isFinish = downLoadHelper.IsFinished;
                            if (isFinish)
                            {
                                Logging.Log4NetHelper.Info(typeof(MainWindowService), string.Format(Resources.Message.ManualDownloadSuccess, manualResponse.SCVERSION));
                            }
                        }
                        else
                        {
                            downLoadHelper.OperateFile.Close();
                            downLoadHelper.OperateFile.Dispose();
                        }


                        string localMd5 = CommonHelper.GetMD5HashFromFile(localFileName);

                        if (localMd5 != manualResponse.MD5)
                        {
                            File.Delete(localFileName);
                        }
                        else
                        {
                            string oldChmPath = AppDomain.CurrentDomain.BaseDirectory + PRO_ReceiptsInvMgr.Resources.Common.ManualFilename;
                            string newChmPath = AppDomain.CurrentDomain.BaseDirectory + downLoadHelper.FileName;
                            if (File.Exists(newChmPath))
                            {
                                if (File.Exists(oldChmPath))
                                {
                                    File.Delete(oldChmPath);
                                }

                                FileInfo fileInfo = new FileInfo(newChmPath);
                                fileInfo.MoveTo(oldChmPath);
                            }

                            myIni.IniWriteValue("InitializeInfo", "ManualVersion", manualResponse.SCVERSION);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logging.Log4NetHelper.Error(typeof(MainWindowService), string.Format(Message.ManualDownloadFail, ex.Message + System.Environment.NewLine + ex.StackTrace));
                }
            }
        }