private bool InitializeDataBase(string dataDirectory, string userName, string password) { bool tmpCreateResult = false; var tmpSQLiteDataBase = new HuiruiSoft.Data.SQLite.GeneralSQLiteDataBase(); tmpSQLiteDataBase.DataSource = string.Format(@"{0}\SafePassData.dat", dataDirectory); tmpSQLiteDataBase.Password = Md5DigestHelper.Md5Salt(password, userName); tmpSQLiteDataBase.CreateDataBase(); var tmpResourceStream = ResourceStreamHelper.GetStream("resources.database.SafePass.sql", typeof(ResourceFinder)); if (tmpResourceStream != null) { byte[] bytes = new byte[tmpResourceStream.Length]; tmpResourceStream.Read(bytes, 0, bytes.Length); string tmpCommandString = System.Text.Encoding.UTF8.GetString(bytes); tmpSQLiteDataBase.ExecuteNonQuery(tmpCommandString); var tmpRootCatalog = new AccountCatalog(); tmpRootCatalog.Depth = 1; tmpRootCatalog.ParentId = -1; tmpRootCatalog.Name = this.textSafePassName.Text; tmpCreateResult = tmpSQLiteDataBase.CreateRootCatalog(tmpRootCatalog); if (tmpCreateResult) { // } } return(tmpCreateResult); }
public static Stream GetResourceStream(string resourceName, string itemName) { string name = string.Format("PreciousUI.Resources.{0}.{1}", resourceName, itemName); Stream stream = ResourceStreamHelper.GetStream(name, Assembly.GetExecutingAssembly()); return(stream); }
private bool CreateLog4NetConfig( ) { bool tmpCreateResult = false; var tmpConfigStream = ResourceStreamHelper.GetStream("resources.config.log4net.config", typeof(ResourceFinder)); if (tmpConfigStream != null) { var tmpConfigDirectory = Path.Combine(Application.StartupPath, "config"); if (!Directory.Exists(tmpConfigDirectory)) { try { Directory.CreateDirectory(tmpConfigDirectory); } catch (System.SystemException exception) { loger.Error(exception); System.Diagnostics.Debug.WriteLine(exception.Message); } } using (var tmpFileStream = new FileStream(Path.Combine(tmpConfigDirectory, "log4net.config"), FileMode.OpenOrCreate, FileAccess.Write)) { byte[] buffer = new byte[tmpConfigStream.Length]; tmpConfigStream.Read(buffer, 0, buffer.Length); tmpFileStream.Write(buffer, 0, buffer.Length); tmpFileStream.Flush(); tmpFileStream.Close(); tmpCreateResult = true; } } return(tmpCreateResult); }