@@ -260,46 +260,54 @@ public QTTabBarClass() {
260
260
ConfigurationManager.AppSettings.Set("EnableWindowsFormsHighDpiAutoResizing", "true");
261
261
}
262
262
catch (Exception) { /* Ignora l'eccezione #1# }*/
263
-
264
263
try {
265
-
266
264
string installDateString ;
267
265
DateTime installDate ;
268
266
string minDate = DateTime . MinValue . ToString ( ) ;
269
267
using ( RegistryKey key = Registry . LocalMachine . OpenSubKey ( RegConst . Root ) ) {
270
268
installDateString = key == null ? minDate : ( string ) key . GetValue ( "InstallDate" , minDate ) ;
271
269
// 时间格式出错, 可能会导致初始化失败
272
- try
273
- {
274
- QTUtility2 . log ( "installDateString " + installDateString ) ;
275
- installDate = DateTime . Parse ( installDateString ) ;
276
- }
277
- catch ( Exception e )
278
- {
279
- installDate = DateTime . ParseExact ( installDateString , "yyyy/MM/dd HH:mm:ss" , CultureInfo . CurrentCulture ) ;
280
- // ignore exception
281
- }
282
- }
283
- using ( RegistryKey key = Registry . CurrentUser . CreateSubKey ( RegConst . Root ) ) {
284
- DateTime lastActivation ;
285
- // DateTime lastActivation = DateTime.Parse((string)key.GetValue("ActivationDate", minDate));
286
- var value = ( string ) key . GetValue ( "ActivationDate" , minDate ) ;
287
- try
270
+ if ( QTUtility . IsSimpleDateStr ( installDateString ) ) // 正则判断日期是否是正确格式
288
271
{
289
- QTUtility2 . log ( "ActivationDate " + value ) ;
290
- lastActivation = DateTime . Parse ( value ) ;
291
- }
292
- catch ( Exception e )
272
+ try
273
+ {
274
+ QTUtility2 . log ( "installDateString " + installDateString ) ;
275
+ installDate = DateTime . Parse ( installDateString ) ;
276
+ }
277
+ catch ( Exception e )
278
+ {
279
+ installDate = DateTime . ParseExact ( installDateString , "yyyy/MM/dd HH:mm:ss" , CultureInfo . CurrentCulture ) ;
280
+ // ignore exception
281
+ }
282
+
283
+ using ( RegistryKey key2 = Registry . CurrentUser . CreateSubKey ( RegConst . Root ) )
284
+ {
285
+ DateTime lastActivation ;
286
+ // DateTime lastActivation = DateTime.Parse((string)key.GetValue("ActivationDate", minDate));
287
+ var value = ( string ) key2 . GetValue ( "ActivationDate" , minDate ) ;
288
+ try
289
+ {
290
+ QTUtility2 . log ( "ActivationDate " + value ) ;
291
+ lastActivation = DateTime . Parse ( value ) ;
292
+ }
293
+ catch ( Exception e )
294
+ {
295
+ lastActivation = DateTime . ParseExact ( value , "yyyy/MM/dd HH:mm:ss" , CultureInfo . CurrentCulture ) ;
296
+ // ignore exception
297
+ }
298
+
299
+ fIsFirstLoad = installDate . CompareTo ( lastActivation ) > 0 ;
300
+ // 时间格式出错, 可能会导致初始化失败
301
+ if ( fIsFirstLoad )
302
+ key . SetValue ( "ActivationDate" , installDateString ) ;
303
+ }
304
+ }
305
+ /*else if (QTUtility.IsShortDateStr(installDateString))
293
306
{
294
- lastActivation = DateTime . ParseExact ( value , "yyyy/MM/dd HH:mm:ss" , CultureInfo . CurrentCulture ) ;
295
- // ignore exception
296
- }
297
307
298
- fIsFirstLoad = installDate . CompareTo ( lastActivation ) > 0 ;
299
- // 时间格式出错, 可能会导致初始化失败
300
- if ( fIsFirstLoad )
301
- key . SetValue ( "ActivationDate" , installDateString ) ;
308
+ }*/
302
309
}
310
+
303
311
}
304
312
catch ( Exception e ) {
305
313
QTUtility2 . MakeErrorLog ( e , "QTTabBarClass 构造函数初始化安装时间" ) ;
0 commit comments