22using System . Collections . Generic ;
33using _1RM . Model . Protocol ;
44using _1RM . Model . Protocol . Base ;
5+ using _1RM . Utils ;
56using Shawn . Utils ;
7+ using static System . Windows . Forms . VisualStyles . VisualStyleElement ;
68
79namespace _1RM . Model . DAO
810{
@@ -18,7 +20,7 @@ public enum DatabaseType
1820 Sqlite ,
1921 }
2022
21- public abstract class IDataBase
23+ public abstract class IDatabase
2224 {
2325 public abstract void CloseConnection ( ) ;
2426 public abstract void OpenConnection ( ) ;
@@ -76,6 +78,24 @@ public abstract class IDataBase
7678
7779 public abstract void SetDataUpdateTimestamp ( long time = - 1 ) ;
7880 public abstract long GetDataUpdateTimestamp ( ) ;
81+
82+ protected void SetEncryptionTest ( )
83+ {
84+ if ( string . IsNullOrEmpty ( GetConfig ( "EncryptionTest" ) ) )
85+ {
86+ SetConfig ( "EncryptionTest" , UnSafeStringEncipher . SimpleEncrypt ( "EncryptionTest" ) ) ;
87+ }
88+ }
89+
90+ public bool CheckEncryptionTest ( )
91+ {
92+ var et = GetConfig ( "EncryptionTest" ) ;
93+ if ( UnSafeStringEncipher . SimpleDecrypt ( et ?? "" ) != "EncryptionTest" )
94+ {
95+ return false ;
96+ }
97+ return true ;
98+ }
7999 }
80100
81101
@@ -92,11 +112,11 @@ public static string GetMysqlConnectionString(string host, int port, string dbNa
92112
93113
94114
95- private static string ? TryGetConfig ( this IDataBase iDataBase , string key )
115+ private static string ? TryGetConfig ( this IDatabase iDatabase , string key )
96116 {
97117 try
98118 {
99- var val = iDataBase . GetConfig ( key ) ?? "" ;
119+ var val = iDatabase . GetConfig ( key ) ?? "" ;
100120 return val ;
101121 }
102122 catch ( Exception e )
@@ -106,11 +126,11 @@ public static string GetMysqlConnectionString(string host, int port, string dbNa
106126 }
107127 }
108128
109- private static bool TrySetConfig ( this IDataBase iDataBase , string key , string value )
129+ private static bool TrySetConfig ( this IDatabase iDatabase , string key , string value )
110130 {
111131 try
112132 {
113- iDataBase . SetConfig ( key , value ?? "" ) ;
133+ iDatabase . SetConfig ( key , value ?? "" ) ;
114134 return true ;
115135 }
116136 catch ( Exception e )
@@ -120,12 +140,12 @@ private static bool TrySetConfig(this IDataBase iDataBase, string key, string va
120140 }
121141 }
122142
123- public static bool CheckWritable ( this IDataBase iDataBase )
143+ public static bool CheckWritable ( this IDatabase iDatabase )
124144 {
125145 try
126146 {
127- iDataBase . SetConfig ( "permission_check" , "true" ) ; // insert
128- iDataBase . SetConfig ( "permission_check" , "true" ) ; // update
147+ iDatabase . SetConfig ( "permission_check" , "true" ) ; // insert
148+ iDatabase . SetConfig ( "permission_check" , "true" ) ; // update
129149 return true ;
130150 }
131151 catch ( Exception e )
@@ -135,11 +155,11 @@ public static bool CheckWritable(this IDataBase iDataBase)
135155 }
136156 }
137157
138- public static bool CheckReadable ( this IDataBase iDataBase )
158+ public static bool CheckReadable ( this IDatabase iDatabase )
139159 {
140160 try
141161 {
142- iDataBase . SetConfig ( "permission_check" , "true" ) ; // update
162+ iDatabase . SetConfig ( "permission_check" , "true" ) ; // update
143163 }
144164 catch
145165 {
@@ -148,7 +168,7 @@ public static bool CheckReadable(this IDataBase iDataBase)
148168
149169 try
150170 {
151- var val = iDataBase . GetConfig ( "permission_check" ) ;
171+ var val = iDatabase . GetConfig ( "permission_check" ) ;
152172 return true ;
153173 }
154174 catch
0 commit comments