Browse Source

代码优化

master
张剑 1 year ago
parent
commit
d99cb134ce
44 changed files with 1284 additions and 1208 deletions
  1. 3
    3
      XHWK.WKTool/App.xaml.cs
  2. 4
    4
      XHWK.WKTool/AppUpdateWin.xaml
  3. 1
    1
      XHWK.WKTool/Controls/MainImage.cs
  4. 0
    0
      XHWK.WKTool/DAL/DalUpload.cs
  5. 1
    1
      XHWK.WKTool/JieTuWindow.xaml.cs
  6. 26
    36
      XHWK.WKTool/MainWindow.xaml.cs
  7. 1
    1
      XHWK.WKTool/ProductVerification.xaml.cs
  8. 2
    2
      XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs
  9. 0
    0
      XHWK.WKTool/Utils/AutoStartHelper.cs
  10. 176
    189
      XHWK.WKTool/Utils/BlackboardNew.cs
  11. 0
    0
      XHWK.WKTool/Utils/CLeopardZip.cs
  12. 0
    0
      XHWK.WKTool/Utils/CameraHelper.cs
  13. 0
    0
      XHWK.WKTool/Utils/DataConvertCommon.cs
  14. 26
    14
      XHWK.WKTool/Utils/DataProvider.cs
  15. 58
    61
      XHWK.WKTool/Utils/DownloadManager.cs
  16. 42
    45
      XHWK.WKTool/Utils/DownloadService.cs
  17. 0
    0
      XHWK.WKTool/Utils/FFMpeg.cs
  18. 0
    0
      XHWK.WKTool/Utils/FileToolsCommon.cs
  19. 12
    6
      XHWK.WKTool/Utils/FreeMemoryHelper.cs
  20. 238
    172
      XHWK.WKTool/Utils/ImageHelper.cs
  21. 153
    186
      XHWK.WKTool/Utils/ImageOperationUtil.cs
  22. 3
    3
      XHWK.WKTool/Utils/JsonHelper.cs
  23. 72
    39
      XHWK.WKTool/Utils/KeyboardHookCommon.cs
  24. 149
    117
      XHWK.WKTool/Utils/LatticeFileHelper.cs
  25. 0
    2
      XHWK.WKTool/Utils/LogHelper.cs
  26. 1
    4
      XHWK.WKTool/Utils/MouseEventCommon.cs
  27. 12
    6
      XHWK.WKTool/Utils/PdfTrunImage.cs
  28. 14
    9
      XHWK.WKTool/Utils/PrimaryScreen.cs
  29. 5
    29
      XHWK.WKTool/Utils/QueueSync.cs
  30. 102
    0
      XHWK.WKTool/Utils/SplashScreen.cs
  31. 21
    22
      XHWK.WKTool/Utils/XmlUtilHelper.cs
  32. 22
    10
      XHWK.WKTool/Utils/ZAsposeUtil.cs
  33. 68
    66
      XHWK.WKTool/Utils/ZAudioRecordHelper.cs
  34. 1
    1
      XHWK.WKTool/Utils/ZClippingBorder.cs
  35. 2
    2
      XHWK.WKTool/Utils/ZConfigAppUtil.cs
  36. 0
    0
      XHWK.WKTool/Utils/ZHttpUtil.cs
  37. 39
    41
      XHWK.WKTool/Utils/ZVideoRecordHelper.cs
  38. 0
    0
      XHWK.WKTool/View/UControl/UC_MultiRangeSlider.xaml
  39. 0
    0
      XHWK.WKTool/View/UControl/UC_MultiRangeSlider.xaml.cs
  40. 0
    0
      XHWK.WKTool/View/UControl/Uc_VideoItem.xaml
  41. 0
    0
      XHWK.WKTool/View/UControl/Uc_VideoItem.xaml.cs
  42. 29
    31
      XHWK.WKTool/XHWK.WKTool.csproj
  43. 1
    1
      XHWK.WKTool/XHWK.WKTool.csproj.user
  44. 0
    104
      XHWK.WKTool/system/SplashScreen.cs

+ 3
- 3
XHWK.WKTool/App.xaml.cs View File

@@ -537,7 +537,7 @@ namespace XHWK.WKTool
537 537
                 if (FileToolsCommon.IsExistFile(saveName))
538 538
                 {
539 539
                     string wkDateXmlStr = FileToolsCommon.FileToString(saveName);
540
-                    WKDataList = XmlUtilHelper.DESerializer<List<ModelWkData>>(wkDateXmlStr);
540
+                    WKDataList = XmlUtilHelper.DeSerializer<List<ModelWkData>>(wkDateXmlStr);
541 541
                     foreach (ModelWkData wklist in WKDataList)
542 542
                     {
543 543
                         //移除找不到视频的微课数据
@@ -597,7 +597,7 @@ namespace XHWK.WKTool
597 597
                 if (FileToolsCommon.IsExistFile(savePath))
598 598
                 {
599 599
                     string pageDataXmlStr = FileToolsCommon.FileToString(savePath);
600
-                    PageDrawList = XmlUtilHelper.DESerializer<List<ModelDrawData>>(pageDataXmlStr);
600
+                    PageDrawList = XmlUtilHelper.DeSerializer<List<ModelDrawData>>(pageDataXmlStr);
601 601
                 }
602 602
                 else
603 603
                 {
@@ -654,7 +654,7 @@ namespace XHWK.WKTool
654 654
                 if (FileToolsCommon.IsExistFile(saveName))
655 655
                 {
656 656
                     string dateXmlStr = FileToolsCommon.FileToString(saveName);
657
-                    ServiceAddress = XmlUtilHelper.DESerializer<ModelServiceAddress>(dateXmlStr);
657
+                    ServiceAddress = XmlUtilHelper.DeSerializer<ModelServiceAddress>(dateXmlStr);
658 658
                     SwitchAddress();
659 659
                 }
660 660
             }

+ 4
- 4
XHWK.WKTool/AppUpdateWin.xaml View File

@@ -18,7 +18,7 @@
18 18
     mc:Ignorable="d">
19 19
 
20 20
     <Grid>
21
-        <views:ZJClippingBorder
21
+        <views:ZClippingBorder
22 22
             Margin="0"
23 23
             Background="#fafafa"
24 24
             BorderBrush="#3f6fff"
@@ -131,7 +131,7 @@
131 131
                             LineHeight="30"
132 132
                             Text="正在更新,已下载0%" />
133 133
 
134
-                        <views:ZJClippingBorder
134
+                        <views:ZClippingBorder
135 135
                             Height="12"
136 136
                             Margin="20,20,20,20"
137 137
                             CornerRadius="6"
@@ -143,10 +143,10 @@
143 143
                                 Foreground="#3f6fff"
144 144
                                 Maximum="100"
145 145
                                 Minimum="0" />
146
-                        </views:ZJClippingBorder>
146
+                        </views:ZClippingBorder>
147 147
                     </StackPanel>
148 148
                 </Grid>
149 149
             </Grid>
150
-        </views:ZJClippingBorder>
150
+        </views:ZClippingBorder>
151 151
     </Grid>
152 152
 </Window>

+ 1
- 1
XHWK.WKTool/Controls/MainImage.cs View File

@@ -696,7 +696,7 @@ namespace ComeCapture.Controls
696 696
         private void OnMove(object sender, MouseEventArgs e)
697 697
         {
698 698
             Point point = PointToScreen(e.GetPosition(this));
699
-            AppModel.Current.ShowRGB = ImageHelper.GetRGB((int)point.X, (int)point.Y);
699
+            AppModel.Current.ShowRGB = ImageHelper.GetRgb((int)point.X, (int)point.Y);
700 700
         }
701 701
 
702 702
         #endregion 刷新RGB

XHWK.WKTool/DAL/DAL_Upload.cs → XHWK.WKTool/DAL/DalUpload.cs View File


+ 1
- 1
XHWK.WKTool/JieTuWindow.xaml.cs View File

@@ -466,7 +466,7 @@ namespace ComeCapture
466 466
             System.Windows.Point screenP = PointToScreen(point);
467 467
             try
468 468
             {
469
-                AppModel.Current.ShowRGB = ImageHelper.GetRGB((int)screenP.X, (int)screenP.Y);
469
+                AppModel.Current.ShowRGB = ImageHelper.GetRgb((int)screenP.X, (int)screenP.Y);
470 470
             }
471 471
             catch (Exception ex)
472 472
             {

+ 26
- 36
XHWK.WKTool/MainWindow.xaml.cs View File

@@ -283,8 +283,8 @@ namespace XHWK.WKTool
283 283
 
284 284
         private async Task CheckDevice()
285 285
         {
286
-            Task<bool> checkMicrophone = Task.Run(() => ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.microphone));
287
-            Task<bool> checkLoudspeaker = Task.Run(() => ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.loudspeaker));
286
+            Task<bool> checkMicrophone = Task.Run(() => ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.Microphone));
287
+            Task<bool> checkLoudspeaker = Task.Run(() => ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.Loudspeaker));
288 288
             await Task.WhenAll(checkMicrophone, checkLoudspeaker);
289 289
             _microphoneGood = checkMicrophone.Result;
290 290
             _loudspeakerGood = checkMicrophone.Result;
@@ -688,7 +688,7 @@ namespace XHWK.WKTool
688 688
             HideAngleBorder();
689 689
             GridPage.Visibility = Visibility.Visible; //页码大于0 显示
690 690
             App.PageContextData.currpage = App.PageContextData.pagenum;
691
-            myblackboard.changepage(App.PageContextData.currpage - 1);
691
+            myblackboard.Changepage(App.PageContextData.currpage - 1);
692 692
             ScroMain.ScrollToVerticalOffset(0);
693 693
             //清空页面图片UI
694 694
             ImgCanvas.Source = null;
@@ -1186,7 +1186,7 @@ namespace XHWK.WKTool
1186 1186
         private void imgCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
1187 1187
         {
1188 1188
             _mouseDown = true;
1189
-            _imageOperationUtil.setMouseDown(_mouseDown);
1189
+            _imageOperationUtil.SetMouseDown(_mouseDown);
1190 1190
         }
1191 1191
 
1192 1192
         /// <summary>
@@ -1425,7 +1425,7 @@ namespace XHWK.WKTool
1425 1425
                     {
1426 1426
                         App.PageContextData.pagenum += 1;
1427 1427
                         App.PageContextData.currpage = App.PageContextData.pagenum;
1428
-                        myblackboard.changepage(App.PageContextData.currpage - 1);
1428
+                        myblackboard.Changepage(App.PageContextData.currpage - 1);
1429 1429
                         GridPage.Visibility = Visibility.Visible; //页码大于0 显示
1430 1430
 
1431 1431
                         #region 插入页码
@@ -1447,7 +1447,7 @@ namespace XHWK.WKTool
1447 1447
                         ImgDocumentation.Source = null;
1448 1448
                         BitmapImage bitImg = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
1449 1449
                         _mouseDown = false;
1450
-                        _imageOperationUtil.setMouseDown(_mouseDown);
1450
+                        _imageOperationUtil.SetMouseDown(_mouseDown);
1451 1451
                         App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
1452 1452
                         {
1453 1453
                             X = 0.1,
@@ -1507,7 +1507,7 @@ namespace XHWK.WKTool
1507 1507
                         () =>
1508 1508
                         {
1509 1509
                             App.myloading.Show();
1510
-                            myblackboard.changepage(App.PageContextData.pagenum);
1510
+                            myblackboard.Changepage(App.PageContextData.pagenum);
1511 1511
                         }
1512 1512
                     );
1513 1513
                     string filepath = _ofd.FileName;
@@ -1817,7 +1817,7 @@ namespace XHWK.WKTool
1817 1817
                                     {
1818 1818
                                         App.PageContextData.pagenum += 1;
1819 1819
                                         App.PageContextData.currpage = App.PageContextData.pagenum;
1820
-                                        myblackboard.changepage(App.PageContextData.currpage - 1);
1820
+                                        myblackboard.Changepage(App.PageContextData.currpage - 1);
1821 1821
                                         GridPage.Visibility = Visibility.Visible; //页码大于0 显示
1822 1822
 
1823 1823
                                         #region 插入页码
@@ -1828,7 +1828,7 @@ namespace XHWK.WKTool
1828 1828
                                     {
1829 1829
                                         App.PageContextData.pagenum += 1;
1830 1830
                                         App.PageContextData.currpage = App.PageContextData.pagenum;
1831
-                                        myblackboard.changepage(App.PageContextData.currpage - 1);
1831
+                                        myblackboard.Changepage(App.PageContextData.currpage - 1);
1832 1832
                                     }
1833 1833
                                     if (App.PageDrawList.Count >= App.PageContextData.currpage)
1834 1834
                                     {
@@ -1845,7 +1845,7 @@ namespace XHWK.WKTool
1845 1845
                                         ImgDocumentation.Source = null;
1846 1846
                                         BitmapImage bitImg = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
1847 1847
                                         _mouseDown = false;
1848
-                                        _imageOperationUtil.setMouseDown(_mouseDown);
1848
+                                        _imageOperationUtil.SetMouseDown(_mouseDown);
1849 1849
                                         App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
1850 1850
                                         {
1851 1851
                                             X = 0.1,
@@ -2694,7 +2694,7 @@ namespace XHWK.WKTool
2694 2694
 
2695 2695
             App.PageContextData.currpage = 0;
2696 2696
             App.PageContextData.pagenum = 0;
2697
-            myblackboard.clear();
2697
+            myblackboard.Clear();
2698 2698
             App.PageDrawList.Clear();
2699 2699
             ImgCanvas.Source = null;
2700 2700
             ImgDocumentation.Source = null;
@@ -2816,12 +2816,7 @@ namespace XHWK.WKTool
2816 2816
                     (
2817 2817
                         () =>
2818 2818
                         {
2819
-                            Bitmap bm = ImageHelper.SaveUI2Bitmap
2820
-                            (
2821
-                                GridMain,
2822
-                                _gridActWidth,
2823
-                                _gridActHeight
2824
-                            );
2819
+                            Bitmap bm = ImageHelper.SaveUi2Bitmap(GridMain, _gridActWidth, _gridActHeight);
2825 2820
                             _videoWriter.WriteVideoFrame(bm);
2826 2821
                             bm.Dispose();
2827 2822
                         }
@@ -2838,7 +2833,6 @@ namespace XHWK.WKTool
2838 2833
             }
2839 2834
         }
2840 2835
 
2841
-        //new WaveInEvent();
2842 2836
         /// <summary>
2843 2837
         /// 开始录制和暂停录制
2844 2838
         /// </summary>
@@ -2853,13 +2847,13 @@ namespace XHWK.WKTool
2853 2847
                     _videoInfo = new ModelVideo { VideoType = (EnumVideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")), WkType = EnumWkVidetype.RecordingLessons };
2854 2848
                     FileToolsCommon.DeleteDirectory(App.WKData.WkPath + "temp/");
2855 2849
                     FileToolsCommon.CreateDirectory(App.WKData.WkPath);
2856
-                    _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "_录制." + _videoInfo.VideoType.ToString();
2857
-                    _tempVideoPathName = App.WKData.WkPath + App.WKData.WkName + "_录制Syn.avi";
2850
+                    _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "." + _videoInfo.VideoType;
2851
+                    _tempVideoPathName = App.WKData.WkPath + App.WKData.WkName + "_temp.avi";
2858 2852
                     int num = 1;
2859 2853
                     while (FileToolsCommon.IsExistFile(_videoSavePathName))
2860 2854
                     {
2861
-                        _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "_录制_" + num + "." + _videoInfo.VideoType.ToString();
2862
-                        _tempVideoPathName = App.WKData.WkPath + App.WKData.WkName + "_录制Syn_" + num + ".avi";
2855
+                        _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "_" + num + "." + _videoInfo.VideoType;
2856
+                        _tempVideoPathName = App.WKData.WkPath + App.WKData.WkName + "_temp_" + num + ".avi";
2863 2857
                         num++;
2864 2858
                     }
2865 2859
                     _tempAudioPathName = _tempVideoPathName.Replace(".avi", ".mp3");
@@ -2867,6 +2861,7 @@ namespace XHWK.WKTool
2867 2861
                     _gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f) / 2) * 2;
2868 2862
                     lock (this)
2869 2863
                     {
2864
+                        Console.WriteLine(@"临时视频存储路径:" + _tempVideoPathName);
2870 2865
                         _videoWriter.Open
2871 2866
                         (
2872 2867
                             _tempVideoPathName,
@@ -2972,7 +2967,7 @@ namespace XHWK.WKTool
2972 2967
         /// </summary>
2973 2968
         private void JumpPageClick()
2974 2969
         {
2975
-            myblackboard.changepage(App.PageContextData.currpage - 1);
2970
+            myblackboard.Changepage(App.PageContextData.currpage - 1);
2976 2971
             ScroMain.ScrollToVerticalOffset(0);
2977 2972
             if (BtnImport.IsEnabled)
2978 2973
             {
@@ -3013,7 +3008,7 @@ namespace XHWK.WKTool
3013 3008
                         if (App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation != null && App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.X > 0)
3014 3009
                         {
3015 3010
                             _mouseDown = false;
3016
-                            _imageOperationUtil.setMouseDown(_mouseDown);
3011
+                            _imageOperationUtil.SetMouseDown(_mouseDown);
3017 3012
                             ImgXy();
3018 3013
                         }
3019 3014
                     }
@@ -3033,7 +3028,7 @@ namespace XHWK.WKTool
3033 3028
             if (App.PageContextData.currpage > 1)
3034 3029
             {
3035 3030
                 _mouseDown = false;
3036
-                _imageOperationUtil.setMouseDown(_mouseDown);
3031
+                _imageOperationUtil.SetMouseDown(_mouseDown);
3037 3032
                 HideAngleBorder();
3038 3033
                 App.PageContextData.currpage -= 1;
3039 3034
                 JumpPageClick();
@@ -3052,7 +3047,7 @@ namespace XHWK.WKTool
3052 3047
             if (App.PageContextData.currpage < App.PageContextData.pagenum)
3053 3048
             {
3054 3049
                 _mouseDown = false;
3055
-                _imageOperationUtil.setMouseDown(_mouseDown);
3050
+                _imageOperationUtil.SetMouseDown(_mouseDown);
3056 3051
                 HideAngleBorder();
3057 3052
                 App.PageContextData.currpage += 1;
3058 3053
                 JumpPageClick();
@@ -3178,8 +3173,7 @@ namespace XHWK.WKTool
3178 3173
                 (
3179 3174
                     () =>
3180 3175
                     {
3181
-                        myblackboard.changepages
3182
-                        (
3176
+                        myblackboard.Changepages(
3183 3177
                             0,
3184 3178
                             0,
3185 3179
                             true,
@@ -3227,8 +3221,7 @@ namespace XHWK.WKTool
3227 3221
                     {
3228 3222
                         //0~1023,亦即有 1024 阶供应用软件后续应用之用,如笔锋笔触,暂无用
3229 3223
                         float pressure = 1.0f * force / 1023f;
3230
-                        myblackboard.changepages
3231
-                        (
3224
+                        myblackboard.Changepages(
3232 3225
                             tempX,
3233 3226
                             tempY,
3234 3227
                             false,
@@ -3302,8 +3295,7 @@ namespace XHWK.WKTool
3302 3295
                 (
3303 3296
                     () =>
3304 3297
                     {
3305
-                        myblackboard.changepages
3306
-                        (
3298
+                        myblackboard.Changepages(
3307 3299
                             0,
3308 3300
                             0,
3309 3301
                             true,
@@ -3988,8 +3980,7 @@ namespace XHWK.WKTool
3988 3980
                     (
3989 3981
                         () =>
3990 3982
                         {
3991
-                            myblackboard.changepages
3992
-                            (
3983
+                            myblackboard.Changepages(
3993 3984
                                 0,
3994 3985
                                 0,
3995 3986
                                 true,
@@ -4017,8 +4008,7 @@ namespace XHWK.WKTool
4017 4008
                         float pressure = bPress / 100f;
4018 4009
                         if (bPress > 0)
4019 4010
                         {
4020
-                            myblackboard.changepages
4021
-                            (
4011
+                            myblackboard.Changepages(
4022 4012
                                 tempX,
4023 4013
                                 tempY,
4024 4014
                                 false,

+ 1
- 1
XHWK.WKTool/ProductVerification.xaml.cs View File

@@ -49,7 +49,7 @@ namespace XHWK.WKTool
49 49
             try
50 50
             {
51 51
                 App.Signature = System.IO.File.ReadAllText(App.DataPath + "signature.txt", Encoding.Default);
52
-                string decrypt = DataProvider.TripleDESDecrypt(App.Signature, App.secretKey);
52
+                string decrypt = DataProvider.TripleDesDecrypt(App.Signature, App.secretKey);
53 53
                 decrypt = decrypt.Replace("\u0001", "").Replace("\u0007", "").Trim();
54 54
                 ModelSignatures msgBean = JsonHelper.JsonToObj<ModelSignatures>(decrypt);
55 55
                 long currentTimeTimestamp = DataProvider.TimestampTotalSeconds(); //当前时间 时间戳

+ 2
- 2
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs View File

@@ -325,9 +325,9 @@ namespace XHWK.WKTool
325 325
                     );
326 326
 
327 327
                     // 麦克风
328
-                    _helper1 = new ZAudioRecordHelper(_tempAudioPathName1, ZAudioRecordHelper.RecordType.microphone);
328
+                    _helper1 = new ZAudioRecordHelper(_tempAudioPathName1, ZAudioRecordHelper.RecordType.Microphone);
329 329
                     // 扬声器
330
-                    _helper2 = new ZAudioRecordHelper(_tempAudioPathName2, ZAudioRecordHelper.RecordType.loudspeaker);
330
+                    _helper2 = new ZAudioRecordHelper(_tempAudioPathName2, ZAudioRecordHelper.RecordType.Loudspeaker);
331 331
                     await Task.Delay(3000);
332 332
                     // App.W_CountdownWindow.Hide();
333 333
                     await Task.Delay(100);

XHWK.WKTool/system/AutoStartHelper.cs → XHWK.WKTool/Utils/AutoStartHelper.cs View File


XHWK.WKTool/system/BlackboardNew.cs → XHWK.WKTool/Utils/BlackboardNew.cs View File

@@ -14,103 +14,113 @@ namespace Common.system
14 14
         Pen = 1,
15 15
         Erase = 2
16 16
     };
17
+
17 18
     /// <summary>
18 19
     /// 画板线模型
19 20
     /// </summary>
20
-    internal class ZBBPage
21
+    internal class ZbbPage
21 22
     {
22 23
         /// <summary>
23 24
         /// 线
24 25
         /// </summary>
25
-        public List<ZBBPageStep> lines { get; set; }
26
+        public List<ZbbPageStep> lines { get; set; }
27
+
26 28
         /// <summary>
27 29
         /// 历史记录
28 30
         /// </summary>
29
-        public List<ZBBPageStep> lines_histoty { get; set; }
31
+        public List<ZbbPageStep> lines_histoty { get; set; }
32
+
30 33
         /// <summary>
31 34
         /// 画板模型
32 35
         /// </summary>
33
-        public ZBBPage()
36
+        public ZbbPage()
34 37
         {
35
-            lines = new List<ZBBPageStep>();
36
-            lines_histoty = new List<ZBBPageStep>();
38
+            lines = new List<ZbbPageStep>();
39
+            lines_histoty = new List<ZbbPageStep>();
37 40
         }
38 41
     }
39 42
 
40
-    internal class ZBBPageStep
43
+    internal class ZbbPageStep
41 44
     {
42 45
         public StrokeCollection lines_curr { get; set; }
43 46
         public StrokeCollection lines_add { get; set; }
44 47
         public StrokeCollection lines_remove { get; set; }
45 48
 
46
-        public ZBBPageStep()
49
+        public ZbbPageStep()
47 50
         {
48 51
             lines_curr = new StrokeCollection();
49 52
             lines_add = new StrokeCollection();
50 53
             lines_remove = new StrokeCollection();
51 54
         }
52 55
     }
56
+
53 57
     public class BlackboardNew
54 58
     {
55
-        private InkCanvas m_canvas;
59
+        private InkCanvas _mCanvas;
56 60
 
57 61
         //private ZPenType type = ZPenType.Pen;
58 62
         /// <summary>
59 63
         /// 当前页索引
60 64
         /// </summary>
61
-        private int pagenum = 0;
65
+        private int _pagenum;
66
+
62 67
         /// <summary>
63 68
         /// 橡皮大小
64 69
         /// </summary>
65
-        private readonly int erasesize = 64;
70
+        private readonly int _erasesize = 64;
71
+
66 72
         /// <summary>
67 73
         /// 笔粗细
68 74
         /// </summary>
69
-        private readonly int pensize = 3;
75
+        private readonly int _pensize = 3;
76
+
70 77
         /// <summary>
71 78
         /// 是否在进行撤销恢复操作
72 79
         /// </summary>
73
-        private int undoOrRedo = 0;
80
+        private int _undoOrRedo;
81
+
74 82
         /// <summary>
75 83
         /// 笔颜色
76 84
         /// </summary>
77
-        private Color pencolor;
85
+        private Color _pencolor;
86
+
78 87
         /// <summary>
79 88
         /// 所有画板线
80 89
         /// </summary>
81
-        private readonly List<ZBBPage> strokes_page_all = new List<ZBBPage>();
90
+        private readonly List<ZbbPage> _strokesPageAll = new List<ZbbPage>();
82 91
 
83 92
         // 添加这个变量是因为在用橡皮擦时 一次操作会触发多次StrokesChanged回掉 这里是把多次回掉合并在一起
84
-        private ZBBPageStep step = null;
93
+        private ZbbPageStep _step;
85 94
 
86 95
         public BlackboardNew(InkCanvas canvas)
87 96
         {
88
-            init(canvas, Colors.White);
97
+            Init(canvas, Colors.White);
89 98
         }
90 99
 
91
-        public BlackboardNew(InkCanvas canvas, Color _pencolor)
100
+        public BlackboardNew(InkCanvas canvas, Color pencolor)
92 101
         {
93
-            init(canvas, _pencolor);
102
+            Init(canvas, pencolor);
94 103
         }
95 104
 
96
-        private DrawingAttributes drawingAttributes;
97
-        private void init(InkCanvas canvas, Color _pencolor)
105
+        private DrawingAttributes _drawingAttributes;
106
+
107
+        private void Init(InkCanvas canvas, Color mpencolor)
98 108
         {
99
-            m_canvas = canvas;
100
-            pencolor = _pencolor;
101
-            ZBBPage page = new ZBBPage();
102
-            page.lines.Add(new ZBBPageStep());
103
-            strokes_page_all.Add(page);
109
+            _mCanvas = canvas;
110
+            this._pencolor = mpencolor;
111
+            ZbbPage page = new ZbbPage();
112
+            page.lines.Add(new ZbbPageStep());
113
+            _strokesPageAll.Add(page);
104 114
             if (canvas != null)
105 115
             {
106 116
                 canvas.EditingMode = InkCanvasEditingMode.Ink;
107
-                drawingAttributes = new DrawingAttributes();
108
-                canvas.DefaultDrawingAttributes = drawingAttributes;
109
-                drawingAttributes.Width = pensize;
110
-                drawingAttributes.Height = pensize;
111
-                drawingAttributes.Color = pencolor;
112
-                drawingAttributes.FitToCurve = true;
113
-                drawingAttributes.IgnorePressure = false;
117
+                _drawingAttributes = new DrawingAttributes();
118
+                canvas.DefaultDrawingAttributes = _drawingAttributes;
119
+                _drawingAttributes.Width = _pensize;
120
+                _drawingAttributes.Height = _pensize;
121
+                _drawingAttributes.Color = this._pencolor;
122
+                _drawingAttributes.FitToCurve = true;
123
+                _drawingAttributes.IgnorePressure = false;
114 124
                 canvas.Strokes.StrokesChanged += Strokes_StrokesChanged;
115 125
                 canvas.StrokeCollected += Canvas_StrokeCollected;
116 126
                 canvas.StrokeErasing += Canvas_StrokeErasing;
@@ -121,47 +131,42 @@ namespace Common.system
121 131
 
122 132
         private void Canvas_StrokeErasing(object sender, InkCanvasStrokeErasingEventArgs e)
123 133
         {
124
-            undoOrRedo = 0;
134
+            _undoOrRedo = 0;
125 135
         }
126 136
 
127
-        private void Canvas_StrokeErased(object sender, RoutedEventArgs e)
128
-        {
129
-        }
137
+        private void Canvas_StrokeErased(object sender, RoutedEventArgs e) { }
130 138
 
131
-        private void Canvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
132
-        {
133
-        }
139
+        private void Canvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e) { }
134 140
 
135 141
         private void Canvas_MouseUp(object sender, MouseButtonEventArgs e)
136 142
         {
137
-            if (step != null)
143
+            if (_step != null)
138 144
             {
139
-                if (pagenum + 1 > strokes_page_all.Count)
145
+                if (_pagenum + 1 > _strokesPageAll.Count)
140 146
                 {
141
-                    ZBBPage pagetemp = new ZBBPage();
142
-                    pagetemp.lines.Add(new ZBBPageStep());
143
-                    strokes_page_all.Add(pagetemp);
147
+                    ZbbPage pagetemp = new ZbbPage();
148
+                    pagetemp.lines.Add(new ZbbPageStep());
149
+                    _strokesPageAll.Add(pagetemp);
144 150
                 }
145
-
146 151
                 try
147 152
                 {
148
-                    ZBBPage page = strokes_page_all[pagenum];
153
+                    ZbbPage page = _strokesPageAll[_pagenum];
149 154
                     if (page != null)
150 155
                     {
151
-                        step.lines_curr.Add(m_canvas.Strokes);
152
-                        page.lines.Add(step);
153
-                        step = null;
156
+                        _step.lines_curr.Add(_mCanvas.Strokes);
157
+                        page.lines.Add(_step);
158
+                        _step = null;
154 159
                     }
155 160
                 }
156 161
                 catch (Exception ex)
157 162
                 {
158
-                    if (strokes_page_all != null)
163
+                    if (_strokesPageAll != null)
159 164
                     {
160
-                        if (strokes_page_all.Count == 0)
165
+                        if (_strokesPageAll.Count == 0)
161 166
                         {
162
-                            ZBBPage pagetemp = new ZBBPage();
163
-                            pagetemp.lines.Add(new ZBBPageStep());
164
-                            strokes_page_all.Add(pagetemp);
167
+                            ZbbPage pagetemp = new ZbbPage();
168
+                            pagetemp.lines.Add(new ZbbPageStep());
169
+                            _strokesPageAll.Add(pagetemp);
165 170
                         }
166 171
                     }
167 172
                     LogHelper.Logerror.Error("【画板】(Canvas_MouseUp)添加失败,strokes_page_all为0," + ex.Message, ex);
@@ -171,122 +176,116 @@ namespace Common.system
171 176
 
172 177
         private void Strokes_StrokesChanged(object sender, StrokeCollectionChangedEventArgs e)
173 178
         {
174
-            if (undoOrRedo > 0)
179
+            if (_undoOrRedo > 0)
175 180
             {
176
-                undoOrRedo -= 1;
181
+                _undoOrRedo -= 1;
177 182
                 return;
178 183
             }
179
-
180
-            if (step == null)
184
+            if (_step == null)
181 185
             {
182
-                step = new ZBBPageStep();
186
+                _step = new ZbbPageStep();
183 187
             }
184 188
 
185 189
             // 笔模式
186 190
             if (e.Added.Count > 0 && e.Removed.Count == 0)
187 191
             {
188
-                step.lines_add.Add(e.Added);
192
+                _step.lines_add.Add(e.Added);
189 193
             }
190 194
             // 橡皮模式 会多次进入回掉
191 195
             else if (e.Removed.Count > 0)
192 196
             {
193
-                step.lines_add.Add(e.Added);
197
+                _step.lines_add.Add(e.Added);
194 198
                 for (int i = 0; i < e.Removed.Count; i++)
195 199
                 {
196 200
                     Stroke removeItem = e.Removed[i];
197
-                    if (step.lines_add.Contains(removeItem))
201
+                    if (_step.lines_add.Contains(removeItem))
198 202
                     {
199
-                        step.lines_add.Remove(removeItem);
203
+                        _step.lines_add.Remove(removeItem);
200 204
                     }
201 205
                     else
202 206
                     {
203
-                        step.lines_remove.Add(removeItem);
207
+                        _step.lines_remove.Add(removeItem);
204 208
                     }
205 209
                 }
206 210
             }
207 211
         }
208 212
 
209 213
         // public方法 笔
210
-        public void change_pen(Color _color)
214
+        public void change_pen(Color color)
211 215
         {
212 216
             //this.type = ZPenType.Pen;
213 217
             DrawingAttributes drawingAttributes = new DrawingAttributes();
214
-            m_canvas.DefaultDrawingAttributes = drawingAttributes;
215
-            drawingAttributes.Color = _color;
216
-            drawingAttributes.Width = pensize;
217
-            drawingAttributes.Height = pensize;
218
+            _mCanvas.DefaultDrawingAttributes = drawingAttributes;
219
+            drawingAttributes.Color = color;
220
+            drawingAttributes.Width = _pensize;
221
+            drawingAttributes.Height = _pensize;
218 222
             drawingAttributes.FitToCurve = true;
219 223
             drawingAttributes.IgnorePressure = false;
220
-            m_canvas.EditingMode = InkCanvasEditingMode.Ink;
224
+            _mCanvas.EditingMode = InkCanvasEditingMode.Ink;
221 225
         }
222 226
 
223 227
         // 橡皮
224 228
         public void change_erase()
225 229
         {
226 230
             //this.type = ZPenType.Erase;
227
-            m_canvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
228
-            m_canvas.EraserShape = new EllipseStylusShape(erasesize, erasesize, 0);
231
+            _mCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
232
+            _mCanvas.EraserShape = new EllipseStylusShape(_erasesize, _erasesize, 0);
229 233
         }
230 234
 
231 235
         // 撤销
232
-        public void undo()
236
+        public void Undo()
233 237
         {
234
-            ZBBPage page = strokes_page_all[pagenum];
235
-
236
-            if (page != null && m_canvas.Strokes.Count > 0 && page.lines.Count > 1)
238
+            ZbbPage page = _strokesPageAll[_pagenum];
239
+            if (page != null && _mCanvas.Strokes.Count > 0 && page.lines.Count > 1)
237 240
             {
238
-                ZBBPageStep last = page.lines.Last();
241
+                ZbbPageStep last = page.lines.Last();
239 242
                 page.lines.Remove(last);
240 243
                 page.lines_histoty.Add(last);
241 244
                 if (page.lines.Last().lines_curr.Count > 0)
242 245
                 {
243
-                    undoOrRedo = 2;
246
+                    _undoOrRedo = 2;
244 247
                 }
245 248
                 else
246 249
                 {
247
-                    undoOrRedo = 1;
250
+                    _undoOrRedo = 1;
248 251
                 }
249
-
250
-                m_canvas.Strokes.Clear();
251
-                m_canvas.Strokes.Add(page.lines.Last().lines_curr);
252
+                _mCanvas.Strokes.Clear();
253
+                _mCanvas.Strokes.Add(page.lines.Last().lines_curr);
252 254
             }
253 255
         }
254 256
 
255 257
         // 恢复
256
-        public void redo()
258
+        public void Redo()
257 259
         {
258
-            ZBBPage page = strokes_page_all[pagenum];
260
+            ZbbPage page = _strokesPageAll[_pagenum];
259 261
             if (page != null && page.lines_histoty.Count > 0)
260 262
             {
261
-                ZBBPageStep line = page.lines_histoty[page.lines_histoty.Count - 1];
262
-
263
+                ZbbPageStep line = page.lines_histoty[page.lines_histoty.Count - 1];
263 264
                 page.lines.Add(line);
264 265
                 page.lines_histoty.Remove(line);
265 266
                 if (page.lines.Last().lines_curr.Count > 0)
266 267
                 {
267
-                    undoOrRedo = 2;
268
+                    _undoOrRedo = 2;
268 269
                 }
269 270
                 else
270 271
                 {
271
-                    undoOrRedo = 1;
272
+                    _undoOrRedo = 1;
272 273
                 }
273
-                m_canvas.Strokes.Clear();
274
-                m_canvas.Strokes.Add(page.lines.Last().lines_curr);
274
+                _mCanvas.Strokes.Clear();
275
+                _mCanvas.Strokes.Add(page.lines.Last().lines_curr);
275 276
             }
276 277
         }
277 278
 
278 279
         // 清空
279
-        public void clear()
280
+        public void Clear()
280 281
         {
281
-
282 282
             //ZBBPage page = new ZBBPage();
283 283
             //page.lines.Add(new ZBBPageStep());
284 284
             //page.lines = new List<ZBBPageStep>();
285 285
             //page.lines_histoty = new List<ZBBPageStep>();
286 286
             //strokes_page_all.Add(page);
287
-
288
-            strokes_page_all.Clear();
289
-            m_canvas.Strokes.Clear();
287
+            _strokesPageAll.Clear();
288
+            _mCanvas.Strokes.Clear();
290 289
             //for (int i=0;i< strokes_page_all.Count;i++)
291 290
             //{
292 291
             //    ZBBPage page = strokes_page_all[pagenum];
@@ -298,171 +297,159 @@ namespace Common.system
298 297
             //        page.lines.Add(new ZBBPageStep());
299 298
             //    }
300 299
             //}
301
-
302
-
303 300
         }
301
+
304 302
         /// <summary>
305 303
         /// 翻页
306 304
         /// </summary>
307 305
         /// <param name="mpagenum"></param>
308
-        public void changepage(int mpagenum)
306
+        public void Changepage(int mpagenum)
309 307
         {
310
-            if (pagenum != mpagenum)
308
+            if (_pagenum != mpagenum)
311 309
             {
312
-                pagenum = mpagenum;
310
+                _pagenum = mpagenum;
313 311
                 //新增页
314
-                if (pagenum >= strokes_page_all.Count)
312
+                if (_pagenum >= _strokesPageAll.Count)
315 313
                 {
316
-                    int numadd = pagenum - strokes_page_all.Count + 1;
314
+                    int numadd = _pagenum - _strokesPageAll.Count + 1;
317 315
                     for (int i = 0; i < numadd; i++)
318 316
                     {
319
-                        ZBBPage pagetemp = new ZBBPage();
320
-                        pagetemp.lines.Add(new ZBBPageStep());
321
-                        strokes_page_all.Add(pagetemp);
317
+                        ZbbPage pagetemp = new ZbbPage();
318
+                        pagetemp.lines.Add(new ZbbPageStep());
319
+                        _strokesPageAll.Add(pagetemp);
322 320
                     }
323 321
                 }
324
-
325
-                ZBBPage page = strokes_page_all[pagenum];
322
+                ZbbPage page = _strokesPageAll[_pagenum];
326 323
                 if (page != null && page.lines.Count > 0)
327 324
                 {
328 325
                     if (page.lines.Last().lines_curr.Count > 0)
329 326
                     {
330
-                        undoOrRedo += 1;
327
+                        _undoOrRedo += 1;
331 328
                     }
332
-                    if (m_canvas.Strokes.Count > 0)
329
+                    if (_mCanvas.Strokes.Count > 0)
333 330
                     {
334
-                        undoOrRedo += 1;
335
-                        m_canvas.Strokes.Clear();
331
+                        _undoOrRedo += 1;
332
+                        _mCanvas.Strokes.Clear();
336 333
                     }
337 334
                     //StrokeCollection strokes = new StrokeCollection();
338
-                    StylusPointCollection stylusPoints = new StylusPointCollection();
335
+                    StylusPointCollection mstylusPoints = new StylusPointCollection();
339 336
                     //System.Windows.Input.StylusPointDescription stylusPointDescription = new StylusPointDescription();
340
-                    StylusPoint stylusPoint = new StylusPoint
341
-                    {
342
-                        X = 580,
343
-                        Y = 212
344
-                    };
345
-                    stylusPoints.Add(stylusPoint);
346
-                    Stroke stroke = new Stroke(stylusPoints);
347
-
348
-                    stylusPoint.X = 581;
349
-                    stylusPoint.Y = 213;
350
-                    stylusPoints.Add(stylusPoint);
351
-                    stroke = new Stroke(stylusPoints);
337
+                    StylusPoint mstylusPoint = new StylusPoint { X = 580, Y = 212 };
338
+                    mstylusPoints.Add(mstylusPoint);
339
+                    Stroke stroke;
340
+                    mstylusPoint.X = 581;
341
+                    mstylusPoint.Y = 213;
342
+                    mstylusPoints.Add(mstylusPoint);
343
+                    stroke = new Stroke(mstylusPoints);
352 344
                     page.lines.Last().lines_curr.Add(stroke);
353
-                    m_canvas.Strokes.Add(page.lines.Last().lines_curr);
345
+                    _mCanvas.Strokes.Add(page.lines.Last().lines_curr);
354 346
                 }
355 347
             }
356 348
         }
357 349
 
358
-        private StylusPointCollection stylusPoints = new StylusPointCollection();
359
-        private StylusPoint stylusPoint = new StylusPoint();
360
-        private Stroke stroke;
361
-        private bool isFirst = true;
362
-        public void changepages(double _x, double _y, bool _new, Color _color, int _size, int i, float Pressure)
350
+        private StylusPointCollection _stylusPoints = new StylusPointCollection();
351
+        private StylusPoint _stylusPoint;
352
+        private Stroke _stroke;
353
+        private bool _isFirst = true;
354
+
355
+        public void Changepages
356
+        (
357
+            double x,
358
+            double y,
359
+            bool mnew,
360
+            Color color,
361
+            int size,
362
+            int i,
363
+            float pressure
364
+        )
363 365
         {
364
-            if (_new)
366
+            if (mnew)
365 367
             {
366
-                if (stroke != null && stroke.StylusPoints.Count > 1)
368
+                if (_stroke != null && _stroke.StylusPoints.Count > 1)
367 369
                 {
368
-                    isFirst = true;
370
+                    _isFirst = true;
369 371
                     try
370 372
                     {
371
-                        if (strokes_page_all.Count <= i)
373
+                        if (_strokesPageAll.Count <= i)
372 374
                         {
373
-                            ZBBPage pagetemp = new ZBBPage();
374
-                            pagetemp.lines.Add(new ZBBPageStep());
375
-                            strokes_page_all.Add(pagetemp);
375
+                            ZbbPage pagetemp = new ZbbPage();
376
+                            pagetemp.lines.Add(new ZbbPageStep());
377
+                            _strokesPageAll.Add(pagetemp);
376 378
                         }
377
-                        strokes_page_all[i].lines.Last().lines_curr.Add(stroke);
379
+                        _strokesPageAll[i].lines.Last().lines_curr.Add(_stroke);
378 380
                     }
379 381
                     catch (Exception ex)
380 382
                     {
381
-                        if (strokes_page_all != null)
383
+                        if (_strokesPageAll != null)
382 384
                         {
383
-                            if (strokes_page_all.Count == 0)
385
+                            if (_strokesPageAll.Count == 0)
384 386
                             {
385
-                                ZBBPage pagetemp = new ZBBPage();
386
-                                pagetemp.lines.Add(new ZBBPageStep());
387
-                                strokes_page_all.Add(pagetemp);
387
+                                ZbbPage pagetemp = new ZbbPage();
388
+                                pagetemp.lines.Add(new ZbbPageStep());
389
+                                _strokesPageAll.Add(pagetemp);
388 390
                             }
389 391
                         }
390 392
                         LogHelper.Logerror.Error("【画板】(changepages)添加失败,strokes_page_all为0," + ex.Message, ex);
391 393
                     }
392 394
                 }
393
-                stylusPoints = new StylusPointCollection();
394
-                stylusPoint = new StylusPoint();
395
-                stroke = null;
395
+                _stylusPoints = new StylusPointCollection();
396
+                _stylusPoint = new StylusPoint();
397
+                _stroke = null;
396 398
             }
397 399
             else
398 400
             {
399
-                if (isFirst)
401
+                if (_isFirst)
400 402
                 {
401
-                    stylusPoint.X = _x;
402
-                    stylusPoint.Y = _y;
403
+                    _stylusPoint.X = x;
404
+                    _stylusPoint.Y = y;
403 405
                     //_color.A = (byte)(Pressure * 255f);
404 406
                     //stylusPoint.PressureFactor = Pressure;
405
-                    stylusPoints.Add(stylusPoint);
406
-                    if (stylusPoints.Count > 1)
407
+                    _stylusPoints.Add(_stylusPoint);
408
+                    if (_stylusPoints.Count > 1)
407 409
                     {
408
-                        stroke = new Stroke(stylusPoints);
409
-                        drawingAttributes = new DrawingAttributes
410
+                        _stroke = new Stroke(_stylusPoints);
411
+                        _drawingAttributes = new DrawingAttributes
410 412
                         {
411
-                            Color = _color,
412
-                            Width = _size * 4.5,
413
-                            Height = _size * 4.5,
413
+                            Color = color,
414
+                            Width = size * 4.5,
415
+                            Height = size * 4.5,
414 416
                             FitToCurve = true,
415 417
                             //IsHighlighter =true,
416 418
                             IgnorePressure = true
417 419
                         };
418
-                        stroke.DrawingAttributes = drawingAttributes;
419
-                        m_canvas.Strokes.Add(stroke);
420
-                        isFirst = false;
420
+                        _stroke.DrawingAttributes = _drawingAttributes;
421
+                        _mCanvas.Strokes.Add(_stroke);
422
+                        _isFirst = false;
421 423
                     }
422 424
                 }
423 425
                 else
424 426
                 {
425
-                    if (m_canvas.Strokes.Count > 0)
427
+                    if (_mCanvas.Strokes.Count > 0)
426 428
                     {
427
-                        stylusPoint.X = _x;
428
-                        stylusPoint.Y = _y;
429
-                        stylusPoints.Add(stylusPoint);
430
-                        stroke = new Stroke(stylusPoints);
431
-                        drawingAttributes = new DrawingAttributes
429
+                        _stylusPoint.X = x;
430
+                        _stylusPoint.Y = y;
431
+                        _stylusPoints.Add(_stylusPoint);
432
+                        _stroke = new Stroke(_stylusPoints);
433
+                        _drawingAttributes = new DrawingAttributes
432 434
                         {
433
-                            Color = _color,
434
-                            Width = _size * 4.5,
435
-                            Height = _size * 4.5,
435
+                            Color = color,
436
+                            Width = size * 4.5,
437
+                            Height = size * 4.5,
436 438
                             FitToCurve = true,
437 439
                             IgnorePressure = false
438 440
                         };
439
-                        stroke.DrawingAttributes = drawingAttributes;
440
-                        m_canvas.Strokes[m_canvas.Strokes.Count - 1] = stroke;
441
+                        _stroke.DrawingAttributes = _drawingAttributes;
442
+                        _mCanvas.Strokes[_mCanvas.Strokes.Count - 1] = _stroke;
441 443
                     }
442 444
                 }
443 445
             }
444 446
         }
445 447
 
446
-
447
-
448
-
449
-
450
-
451
-
452
-
453
-
454
-
455
-
456
-
457
-
458
-
459
-
460
-
461
-        //public void changepages(double _x, double _y, bool _new, Color _color, int _size, int i)
448
+        //public void changepages(double _x, double _y, bool mnew, Color _color, int _size, int i)
462 449
         //{
463 450
         //    try
464 451
         //    {
465
-        //        if (_new)
452
+        //        if (mnew)
466 453
         //        {
467 454
         //            if (stroke != null && stroke.StylusPoints.Count > 1)
468 455
         //            {
@@ -508,4 +495,4 @@ namespace Common.system
508 495
         //    }
509 496
         //}
510 497
     }
511
-}
498
+}

XHWK.WKTool/system/CLeopardZip.cs → XHWK.WKTool/Utils/CLeopardZip.cs View File


XHWK.WKTool/system/CameraHelper.cs → XHWK.WKTool/Utils/CameraHelper.cs View File


XHWK.WKTool/system/DataConvertCommon.cs → XHWK.WKTool/Utils/DataConvertCommon.cs View File


XHWK.WKTool/system/DataProvider.cs → XHWK.WKTool/Utils/DataProvider.cs View File

@@ -8,41 +8,53 @@ namespace Common.system
8 8
     public class DataProvider
9 9
     {
10 10
         ///3DES解密   
11
-        public static string TripleDESDecrypt(string pToDecrypt, string sKey)
11
+        public static string TripleDesDecrypt(string pToDecrypt, string sKey)
12 12
         {
13 13
             sKey = sKey.Substring(0, 24);
14
-            TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider
15
-            {
16
-                Mode = CipherMode.ECB,
17
-                Padding = PaddingMode.Zeros
18
-            };
14
+            TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider { Mode = CipherMode.ECB, Padding = PaddingMode.Zeros };
19 15
             byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
20 16
             for (int x = 0; x < pToDecrypt.Length / 2; x++)
21 17
             {
22 18
                 int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
23 19
                 inputByteArray[x] = (byte)i;
24 20
             }
25
-
26
-            des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
27
-            des.IV = new byte[] { 0, 00, 00, 00, 00, 00, 00, 00, };
21
+            des.Key = Encoding.ASCII.GetBytes(sKey);
22
+            des.IV = new byte[]
23
+            {
24
+                0,
25
+                00,
26
+                00,
27
+                00,
28
+                00,
29
+                00,
30
+                00,
31
+                00,
32
+            };
28 33
             MemoryStream ms = new MemoryStream();
29 34
             CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
30 35
             cs.Write(inputByteArray, 0, inputByteArray.Length);
31 36
             cs.FlushFinalBlock();
32
-
33
-            StringBuilder ret = new StringBuilder();
34
-
35 37
             return System.Text.Encoding.Default.GetString(ms.ToArray()).Replace("\0", "");
36 38
         }
39
+
37 40
         /// <summary>
38 41
         /// 返回一个时间戳到秒
39 42
         /// </summary>
40 43
         /// <returns></returns>
41 44
         public static long TimestampTotalSeconds()
42 45
         {
43
-            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
46
+            TimeSpan ts = DateTime.UtcNow -
47
+            new DateTime(
48
+                1970,
49
+                1,
50
+                1,
51
+                0,
52
+                0,
53
+                0,
54
+                0
55
+            );
44 56
             long timestr = Convert.ToInt64(ts.TotalSeconds);
45 57
             return timestr;
46 58
         }
47 59
     }
48
-}
60
+}

XHWK.WKTool/system/DownloadManager.cs → XHWK.WKTool/Utils/DownloadManager.cs View File

@@ -15,11 +15,12 @@ namespace Common.system
15 15
     /// </summary>
16 16
     public class DownloadManager
17 17
     {
18
-        private long fromIndex = 0;//开始下载的位置
19
-        private bool isRun = false;//是否正在进行
20
-        private DownloadInfoModel dlInfo;
18
+        private long _fromIndex; //开始下载的位置
19
+        private bool _isRun; //是否正在进行
20
+        private DownloadInfoModel _dlInfo;
21
+
22
+        private List<DownloadService> _dls = new List<DownloadService>();
21 23
 
22
-        private List<DownloadService> dls = new List<DownloadService>();
23 24
         /// <summary>
24 25
         /// 开始下载
25 26
         /// </summary>
@@ -43,15 +44,15 @@ namespace Common.system
43 44
 
44 45
         public DownloadManager(DownloadInfoModel dlInfo)
45 46
         {
46
-            this.dlInfo = dlInfo;
47
+            this._dlInfo = dlInfo;
47 48
         }
48 49
         /// <summary>
49 50
         /// 暂停
50 51
         /// </summary>
51 52
         public void Stop()
52 53
         {
53
-            isRun = false;
54
-            dls.ForEach(dl => dl.Stop());
54
+            _isRun = false;
55
+            _dls.ForEach(dl => dl.Stop());
55 56
             OnStopHandler();
56 57
         }
57 58
         /// <summary>
@@ -59,7 +60,7 @@ namespace Common.system
59 60
         /// </summary>
60 61
         public void Start()
61 62
         {
62
-            dlInfo.isReStart = false;
63
+            _dlInfo.isReStart = false;
63 64
             WorkStart();
64 65
         }
65 66
         /// <summary>
@@ -67,7 +68,7 @@ namespace Common.system
67 68
         /// </summary>
68 69
         public void ReStart()
69 70
         {
70
-            dlInfo.isReStart = true;
71
+            _dlInfo.isReStart = true;
71 72
             WorkStart();
72 73
         }
73 74
         /// <summary>
@@ -77,14 +78,13 @@ namespace Common.system
77 78
         {
78 79
             new Action(() =>
79 80
             {
80
-                if (dlInfo.isReStart)
81
+                if (_dlInfo.isReStart)
81 82
                 {
82 83
                     Stop();
83 84
                 }
84
-
85
-                while (dls.Where(dl => !dl.isStopped).Count() > 0)
85
+                while (_dls.Where(dl => !dl.isStopped).Count() > 0)
86 86
                 {
87
-                    if (dlInfo.isReStart)
87
+                    if (_dlInfo.isReStart)
88 88
                     {
89 89
                         Thread.Sleep(100);
90 90
                     }
@@ -93,90 +93,85 @@ namespace Common.system
93 93
                         return;
94 94
                     }
95 95
                 }
96
-
97
-                isRun = true;
96
+                _isRun = true;
98 97
                 OnStartHandler();
99 98
                 //首次任务或者不支持断点续传的进入
100
-                if (dlInfo.isNewTask || (!dlInfo.isNewTask && !dlInfo.IsSupportMultiThreading))
99
+                if (_dlInfo.isNewTask || (!_dlInfo.isNewTask && !_dlInfo.IsSupportMultiThreading))
101 100
                 {
102 101
                     try
103 102
                     {
104 103
                         //第一次请求获取一小块数据,根据返回的情况判断是否支持断点续传
105
-                        using (System.Net.WebResponse rsp = ZHttpUtil.Download
106
-                               (
107
-                                   dlInfo.downloadUrlList[0],
104
+                        using (System.Net.WebResponse rsp = ZHttpUtil.Download(
105
+                                   _dlInfo.downloadUrlList[0],
108 106
                                    0,
109 107
                                    0,
110
-                                   dlInfo.method
108
+                                   _dlInfo.method
111 109
                                ))
112 110
                         {
113 111
                             //获取文件名,如果包含附件名称则取下附件,否则从url获取名称
114
-                            string Disposition = rsp.Headers["Content-Disposition"];
112
+                            string disposition = rsp.Headers["Content-Disposition"];
115 113
                             try
116 114
                             {
117
-                                if (Disposition != null)
115
+                                if (disposition != null)
118 116
                                 {
119
-                                    dlInfo.fileName = Disposition.Split('=')[1];
117
+                                    _dlInfo.fileName = disposition.Split('=')[1];
120 118
                                 }
121 119
                                 else
122 120
                                 {
123
-                                    dlInfo.fileName = Path.GetFileName(rsp.ResponseUri.AbsolutePath);
121
+                                    _dlInfo.fileName = Path.GetFileName(rsp.ResponseUri.AbsolutePath);
124 122
                                 }
125 123
                             }
126 124
                             catch (Exception) //无法获取文件名时  使用传入保存名称
127 125
                             {
128
-                                dlInfo.fileName = dlInfo.saveFileName;
126
+                                _dlInfo.fileName = _dlInfo.saveFileName;
129 127
                             }
130 128
 
131 129
                             //默认给流总数
132
-                            dlInfo.count = rsp.ContentLength;
130
+                            _dlInfo.count = rsp.ContentLength;
133 131
                             //尝试获取 Content-Range 头部,不为空说明支持断点续传
134 132
                             string contentRange = rsp.Headers["Content-Range"];
135 133
                             if (contentRange != null)
136 134
                             {
137 135
                                 //支持断点续传的话,就取range 这里的总数
138
-                                dlInfo.count = long.Parse(rsp.Headers["Content-Range"].Split('/')[1]);
139
-                                dlInfo.IsSupportMultiThreading = true;
136
+                                _dlInfo.count = long.Parse(rsp.Headers["Content-Range"].Split('/')[1]);
137
+                                _dlInfo.IsSupportMultiThreading = true;
140 138
 
141 139
                                 //生成一个临时文件名
142 140
                                 //var tempFileName = Convert.ToBase64String(Encoding.UTF8.GetBytes(dlInfo.fileName)).ToUpper();
143 141
                                 //tempFileName = tempFileName.Length > 32 ? tempFileName.Substring(0, 32) : tempFileName;
144 142
                                 //dlInfo.tempFileName = "test"; //tempFileName + DateTime.Now.ToString("yyyyMMddHHmmssfff");
145
-                                ///创建线程信息
146
-                                ///
147
-                                GetTaskInfo(dlInfo);
143
+                                GetTaskInfo(_dlInfo);
148 144
                             }
149 145
                             else
150 146
                             {
151 147
                                 //不支持断点续传则一开始就直接读完整流
152
-                                Save(GetRealFileName(dlInfo), rsp.GetResponseStream());
148
+                                Save(GetRealFileName(_dlInfo), rsp.GetResponseStream());
153 149
                                 OnFineshHandler();
154 150
                             }
155 151
                         }
156 152
                     }
157 153
                     catch (Exception ex)
158 154
                     {
159
-                        string ErrMessage = "【下载】(DownloadManager):" + ex.Message;
160
-                        LogHelper.Logerror.Error(ErrMessage, ex);
155
+                        string errMessage = "【下载】(DownloadManager):" + ex.Message;
156
+                        LogHelper.Logerror.Error(errMessage, ex);
161 157
                         OnDisconnectHandler();
162 158
                         return;
163 159
                     }
164
-                    dlInfo.isNewTask = false;
160
+                    _dlInfo.isNewTask = false;
165 161
                 }
166 162
                 //如果支持断点续传采用这个
167
-                if (dlInfo.IsSupportMultiThreading)
163
+                if (_dlInfo.IsSupportMultiThreading)
168 164
                 {
169
-                    StartTask(dlInfo);
165
+                    StartTask(_dlInfo);
170 166
 
171 167
                     //等待合并
172
-                    while (dls.Where(td => !td.isFinish).Count() > 0 && isRun)
168
+                    while (_dls.Count(td => !td.isFinish) > 0 && _isRun)
173 169
                     {
174 170
                         Thread.Sleep(100);
175 171
                     }
176
-                    if ((dls.Where(td => !td.isFinish).Count() == 0))
172
+                    if ((_dls.Count(td => !td.isFinish) == 0))
177 173
                     {
178
-
179
-                        CombineFiles(dlInfo);
174
+                        CombineFiles(_dlInfo);
180 175
                         OnFineshHandler();
181 176
                     }
182 177
                 }
@@ -231,7 +226,7 @@ namespace Common.system
231 226
 
232 227
         private void StartTask(DownloadInfoModel dlInfo)
233 228
         {
234
-            dls = new List<DownloadService>();
229
+            _dls = new List<DownloadService>();
235 230
             if (dlInfo.TaskInfoList != null)
236 231
             {
237 232
                 foreach (TaskInfoModel item in dlInfo.TaskInfoList)
@@ -239,15 +234,15 @@ namespace Common.system
239 234
                     DownloadService dl = new DownloadService();
240 235
                     dl.OnDownload += OnDownloadHandler;
241 236
                     dl.OnDisconnect += OnDisconnectHandler;
242
-                    dls.Add(dl);
237
+                    _dls.Add(dl);
243 238
                     try
244 239
                     {
245 240
                         dl.Start(item, dlInfo.isReStart);
246 241
                     }
247 242
                     catch (Exception ex)
248 243
                     {
249
-                        string ErrMessage = "【下载】(DownloadManager):" + ex.Message;
250
-                        LogHelper.Logerror.Error(ErrMessage, ex);
244
+                        string errMessage = "【下载】(DownloadManager):" + ex.Message;
245
+                        LogHelper.Logerror.Error(errMessage, ex);
251 246
                     }
252 247
                 }
253 248
             }
@@ -310,14 +305,14 @@ namespace Common.system
310 305
                     {
311 306
                         int repeatTimes = 0;
312 307
                         byte[] buffer = new byte[1024];
313
-                        int length = 0;
314
-                        while ((length = stream.Read(buffer, 0, buffer.Length)) > 0 && isRun)
308
+                        int length;
309
+                        while ((length = stream.Read(buffer, 0, buffer.Length)) > 0 && _isRun)
315 310
                         {
316 311
                             writer.Write(buffer, 0, length);
317
-                            fromIndex += length;
312
+                            _fromIndex += length;
318 313
                             if (repeatTimes % 5 == 0)
319 314
                             {
320
-                                writer.Flush();//一定大小就刷一次缓冲区
315
+                                writer.Flush(); //一定大小就刷一次缓冲区
321 316
                                 OnDownloadHandler();
322 317
                             }
323 318
                             repeatTimes++;
@@ -340,7 +335,10 @@ namespace Common.system
340 335
         {
341 336
             new Action(() =>
342 337
             {
343
-                OnStart.Invoke();
338
+                if (OnStart != null)
339
+                {
340
+                    OnStart.Invoke();
341
+                }
344 342
             }).BeginInvoke(null, null);
345 343
         }
346 344
         /// <summary>
@@ -350,7 +348,7 @@ namespace Common.system
350 348
         {
351 349
             new Action(() =>
352 350
             {
353
-                OnStop.Invoke();
351
+                OnStop?.Invoke();
354 352
             }).BeginInvoke(null, null);
355 353
         }
356 354
         /// <summary>
@@ -360,12 +358,12 @@ namespace Common.system
360 358
         {
361 359
             new Action(() =>
362 360
             {
363
-                for (int i = 0; i < dlInfo.TaskInfoList.Count; i++)
361
+                for (int i = 0; i < _dlInfo.TaskInfoList.Count; i++)
364 362
                 {
365
-                    string tempFile = dlInfo.TaskInfoList[i].filePath;
363
+                    string tempFile = _dlInfo.TaskInfoList[i].filePath;
366 364
                     File.Delete(tempFile);
367 365
                 }
368
-                OnFinsh.Invoke(dlInfo.saveFileName);
366
+                OnFinsh?.Invoke(_dlInfo.saveFileName);
369 367
             }).BeginInvoke(null, null);
370 368
         }
371 369
         /// <summary>
@@ -376,7 +374,7 @@ namespace Common.system
376 374
             new Action(() =>
377 375
             {
378 376
                 long current = GetDownloadLength();
379
-                OnDownload.Invoke(current, dlInfo.count, dlInfo.saveFileName);
377
+                OnDownload?.Invoke(current, _dlInfo.count, _dlInfo.saveFileName);
380 378
             }).BeginInvoke(null, null);
381 379
         }
382 380
         /// <summary>
@@ -386,7 +384,7 @@ namespace Common.system
386 384
         {
387 385
             new Action(() =>
388 386
             {
389
-                OnDisconnect.Invoke(dlInfo.saveFileName);
387
+                OnDisconnect?.Invoke(_dlInfo.saveFileName);
390 388
             }).BeginInvoke(null, null);
391 389
         }
392 390
         /// <summary>
@@ -395,13 +393,13 @@ namespace Common.system
395 393
         /// <returns></returns>
396 394
         public long GetDownloadLength()
397 395
         {
398
-            if (dlInfo.IsSupportMultiThreading)
396
+            if (_dlInfo.IsSupportMultiThreading)
399 397
             {
400
-                return dls.Sum(dl => dl.GetDownloadedCount());
398
+                return _dls.Sum(dl => dl.GetDownloadedCount());
401 399
             }
402 400
             else
403 401
             {
404
-                return fromIndex;
402
+                return _fromIndex;
405 403
             }
406 404
         }
407 405
 
@@ -409,7 +407,6 @@ namespace Common.system
409 407
         /// 获取保存文件名
410 408
         /// </summary>
411 409
         /// <returns></returns>
412
-        public DownloadInfoModel GetFileInfo => dlInfo;
413
-
410
+        public DownloadInfoModel GetFileInfo => _dlInfo;
414 411
     }
415 412
 }

XHWK.WKTool/system/DownloadService.cs → XHWK.WKTool/Utils/DownloadService.cs View File

@@ -13,17 +13,16 @@ namespace Common.system
13 13
     /// </summary>
14 14
     public class DownloadService
15 15
     {
16
-        private string downloadUrl = "";//文件下载地址
17
-        private string filePath = "";//文件保存路径
18
-        private string method = "";//方法
19
-        private long fromIndex = 0;//开始下载的位置
20
-        private long toIndex = 0;//结束下载的位置
21
-        private long count = 0;//总大小
22
-        private long size = 524288;//每次下载大小 512kb
23
-        private bool isRun = false;//是否正在进行
16
+        private string _downloadUrl = ""; //文件下载地址
17
+        private string _filePath = ""; //文件保存路径
18
+        private string _method = ""; //方法
19
+        private long _fromIndex; //开始下载的位置
20
+        private long _toIndex; //结束下载的位置
21
+        private long _count; //总大小
22
+        private readonly long _size = 524288; //每次下载大小 512kb
23
+        private bool _isRun; //是否正在进行
24 24
 
25
-
26
-        public bool isFinish = false;//是否已下载完成{ get; private set; }
25
+        public bool isFinish; //是否已下载完成{ get; private set; }
27 26
 
28 27
         public bool isStopped = true;//是否已停止{ get; private set; }
29 28
 
@@ -47,12 +46,12 @@ namespace Common.system
47 46
 
48 47
         public long GetDownloadedCount()
49 48
         {
50
-            return count - toIndex + fromIndex - 1;
49
+            return _count - _toIndex + _fromIndex - 1;
51 50
         }
52 51
 
53 52
         public void Stop()
54 53
         {
55
-            isRun = false;
54
+            _isRun = false;
56 55
         }
57 56
 
58 57
         /// <summary>
@@ -63,30 +62,30 @@ namespace Common.system
63 62
         /// <returns></returns>
64 63
         public bool Start(TaskInfoModel info, bool isReStart)
65 64
         {
66
-            downloadUrl = info.downloadUrl;
67
-            fromIndex = info.fromIndex;
68
-            toIndex = info.toIndex;
69
-            method = info.method;
70
-            filePath = info.filePath;
71
-            count = info.count;
65
+            _downloadUrl = info.downloadUrl;
66
+            _fromIndex = info.fromIndex;
67
+            _toIndex = info.toIndex;
68
+            _method = info.method;
69
+            _filePath = info.filePath;
70
+            _count = info.count;
72 71
             isStopped = false;
73
-            if (File.Exists(filePath))
72
+            if (File.Exists(_filePath))
74 73
             {
75 74
                 if (isReStart)
76 75
                 {
77
-                    File.Delete(filePath);
78
-                    File.Create(filePath).Close();
76
+                    File.Delete(_filePath);
77
+                    File.Create(_filePath).Close();
79 78
                 }
80 79
             }
81 80
             else
82 81
             {
83
-                File.Create(filePath).Close();
82
+                File.Create(_filePath).Close();
84 83
             }
85
-            using (FileStream file = File.Open(filePath, FileMode.Open))
84
+            using (FileStream file = File.Open(_filePath, FileMode.Open))
86 85
             {
87
-                fromIndex = info.fromIndex + file.Length;
86
+                _fromIndex = info.fromIndex + file.Length;
88 87
             }
89
-            if (fromIndex >= toIndex)
88
+            if (_fromIndex >= _toIndex)
90 89
             {
91 90
                 OnFineshHandler();
92 91
                 isFinish = true;
@@ -94,48 +93,46 @@ namespace Common.system
94 93
                 return false;
95 94
             }
96 95
             OnStartHandler();
97
-            isRun = true;
96
+            _isRun = true;
98 97
             new Action(() =>
99 98
             {
100
-                WebResponse rsp;
101
-                while (fromIndex < toIndex && isRun)
99
+                while (_fromIndex < _toIndex && _isRun)
102 100
                 {
103 101
                     long to;
104
-                    if (fromIndex + size >= toIndex - 1)
102
+                    if (_fromIndex + _size >= _toIndex - 1)
105 103
                     {
106
-                        to = toIndex - 1;
104
+                        to = _toIndex - 1;
107 105
                     }
108 106
                     else
109 107
                     {
110
-                        to = fromIndex + size;
108
+                        to = _fromIndex + _size;
111 109
                     }
112 110
                     try
113 111
                     {
114
-                        using (rsp = ZHttpUtil.Download
115
-                               (
116
-                                   downloadUrl,
117
-                                   fromIndex,
112
+                        WebResponse rsp;
113
+                        using (rsp = ZHttpUtil.Download(
114
+                                   _downloadUrl,
115
+                                   _fromIndex,
118 116
                                    to,
119
-                                   method
117
+                                   _method
120 118
                                ))
121 119
                         {
122
-                            Save(filePath, rsp.GetResponseStream());
120
+                            Save(_filePath, rsp.GetResponseStream());
123 121
                         }
124 122
                     }
125 123
                     catch (Exception ex)
126 124
                     {
127
-                        string ErrMessage = "【下载】(DownloadService):" + ex.Message;
128
-                        LogHelper.Logerror.Error(ErrMessage, ex);
125
+                        string errMessage = "【下载】(DownloadService):" + ex.Message;
126
+                        LogHelper.Logerror.Error(errMessage, ex);
129 127
                         OnDisconnectHandler();
130 128
                         return;
131 129
                     }
132 130
                 }
133
-                if (!isRun)
131
+                if (!_isRun)
134 132
                 {
135 133
                     isStopped = true;
136 134
                 }
137
-
138
-                if (fromIndex >= toIndex)
135
+                if (_fromIndex >= _toIndex)
139 136
                 {
140 137
                     isFinish = true;
141 138
                     isStopped = true;
@@ -160,11 +157,11 @@ namespace Common.system
160 157
                     {
161 158
                         int repeatTimes = 0;
162 159
                         byte[] buffer = new byte[1024];
163
-                        int length = 0;
164
-                        while ((length = stream.Read(buffer, 0, buffer.Length)) > 0 && isRun)
160
+                        int length;
161
+                        while ((length = stream.Read(buffer, 0, buffer.Length)) > 0 && _isRun)
165 162
                         {
166 163
                             writer.Write(buffer, 0, length);
167
-                            fromIndex += length;
164
+                            _fromIndex += length;
168 165
                             if (repeatTimes % 5 == 0)
169 166
                             {
170 167
                                 OnDownloadHandler();

XHWK.WKTool/system/FFMpeg.cs → XHWK.WKTool/Utils/FFMpeg.cs View File


XHWK.WKTool/system/FileToolsCommon.cs → XHWK.WKTool/Utils/FileToolsCommon.cs View File


XHWK.WKTool/system/FreeMemoryHelper.cs → XHWK.WKTool/Utils/FreeMemoryHelper.cs View File

@@ -36,9 +36,12 @@ namespace Common.system
36 36
             CreateKey();
37 37
             RegistryKey currentUser = Registry.CurrentUser;
38 38
             RegistryKey registryKey = currentUser.OpenSubKey("SOFTWARE\\DevExpress\\Components", writable: true);
39
-            registryKey.GetValue("LastAboutShowedTime");
40
-            string value = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
41
-            registryKey.SetValue("LastAboutShowedTime", value);
39
+            if (registryKey != null)
40
+            {
41
+                registryKey.GetValue("LastAboutShowedTime");
42
+                string value = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
43
+                registryKey.SetValue("LastAboutShowedTime", value);
44
+            }
42 45
             currentUser.Dispose();
43 46
         }
44 47
 
@@ -49,9 +52,12 @@ namespace Common.system
49 52
             if (currentUser.OpenSubKey("SOFTWARE\\DevExpress\\Components", writable: true) == null)
50 53
             {
51 54
                 RegistryKey registryKey = currentUser.CreateSubKey("SOFTWARE\\DevExpress\\Components");
52
-                registryKey.CreateSubKey("LastAboutShowedTime").SetValue("LastAboutShowedTime", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"));
53
-                registryKey.CreateSubKey("DisableSmartTag").SetValue("LastAboutShowedTime", false);
54
-                registryKey.CreateSubKey("SmartTagWidth").SetValue("LastAboutShowedTime", 350);
55
+                if (registryKey != null)
56
+                {
57
+                    registryKey.CreateSubKey("LastAboutShowedTime")?.SetValue("LastAboutShowedTime", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"));
58
+                    registryKey.CreateSubKey("DisableSmartTag")?.SetValue("LastAboutShowedTime", false);
59
+                    registryKey.CreateSubKey("SmartTagWidth")?.SetValue("LastAboutShowedTime", 350);
60
+                }
55 61
             }
56 62
 
57 63
             currentUser.Dispose();

XHWK.WKTool/system/ImageHelper.cs → XHWK.WKTool/Utils/ImageHelper.cs View File

@@ -3,7 +3,6 @@ using System.Drawing;
3 3
 using System.Drawing.Imaging;
4 4
 using System.IO;
5 5
 using System.Text;
6
-using System.Threading;
7 6
 using System.Windows;
8 7
 using System.Windows.Media;
9 8
 using System.Windows.Media.Imaging;
@@ -29,9 +28,10 @@ namespace Common.system
29 28
                 if (File.Exists(path))
30 29
                 {
31 30
                     FileStream fs = File.OpenRead(path); //OpenRead
32
-                    int filelength = 0;
31
+                    int filelength;
33 32
                     filelength = (int)fs.Length; //获得文件长度
34 33
                     byte[] image = new byte[filelength]; //建立一个字节数组
34
+                    // ReSharper disable once MustUseReturnValue
35 35
                     fs.Read(image, 0, filelength); //按字节流读取
36 36
                     System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
37 37
                     fs.Close();
@@ -61,9 +61,10 @@ namespace Common.system
61 61
                 if (File.Exists(path))
62 62
                 {
63 63
                     FileStream fs = File.OpenRead(path); //OpenRead
64
-                    int filelength = 0;
64
+                    int filelength;
65 65
                     filelength = (int)fs.Length; //获得文件长度
66 66
                     byte[] image = new byte[filelength]; //建立一个字节数组
67
+                    // ReSharper disable once MustUseReturnValue
67 68
                     fs.Read(image, 0, filelength); //按字节流读取
68 69
                     System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
69 70
                     fs.Close();
@@ -87,18 +88,15 @@ namespace Common.system
87 88
         /// <returns></returns>
88 89
         public static BitmapImage ReadBitmapImageFile(string path)
89 90
         {
90
-            BitmapImage bitmap = new BitmapImage();
91
+            BitmapImage bitmap;
91 92
             try
92 93
             {
93 94
                 using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(path)))
94 95
                 {
95
-                    bitmap = new BitmapImage
96
-                    {
97
-                        DecodePixelHeight = 100
98
-                    };
96
+                    bitmap = new BitmapImage { DecodePixelHeight = 100 };
99 97
                     bitmap.BeginInit();
100
-                    bitmap.CacheOption = BitmapCacheOption.OnLoad;//设置缓存模式
101
-                    bitmap.StreamSource = ms;//通过StreamSource加载图片
98
+                    bitmap.CacheOption = BitmapCacheOption.OnLoad; //设置缓存模式
99
+                    bitmap.StreamSource = ms; //通过StreamSource加载图片
102 100
                     bitmap.EndInit();
103 101
                     bitmap.Freeze();
104 102
                 }
@@ -112,30 +110,28 @@ namespace Common.system
112 110
 
113 111
         #region 获取RGB
114 112
 
115
-        private static Bitmap _Bitmap = null;
116
-        private static StringBuilder sb = new StringBuilder();
113
+        private static Bitmap _bitmap;
114
+        private static StringBuilder _sb = new StringBuilder();
117 115
 
118
-        public static string GetRGB(int x, int y)
116
+        public static string GetRgb(int x, int y)
119 117
         {
120
-            sb = new StringBuilder();
118
+            _sb = new StringBuilder();
121 119
             try
122 120
             {
123
-                System.Drawing.Color color = _Bitmap.GetPixel(x, y);
124
-
125
-                sb.Append("RGB:(");
126
-                sb.Append(color.R.ToString());
127
-                sb.Append(",");
128
-                sb.Append(color.G.ToString());
129
-                sb.Append(",");
130
-                sb.Append(color.B.ToString());
131
-                sb.Append(")");
121
+                System.Drawing.Color color = _bitmap.GetPixel(x, y);
122
+                _sb.Append("RGB:(");
123
+                _sb.Append(color.R.ToString());
124
+                _sb.Append(",");
125
+                _sb.Append(color.G.ToString());
126
+                _sb.Append(",");
127
+                _sb.Append(color.B.ToString());
128
+                _sb.Append(")");
132 129
             }
133 130
             catch (Exception ex)
134 131
             {
135 132
                 LogHelper.Logerror.Error("ImageHelper(GetRGB)" + ex.Message, ex);
136 133
             }
137
-
138
-            return sb.ToString();
134
+            return _sb.ToString();
139 135
         }
140 136
 
141 137
         #endregion 获取RGB
@@ -145,43 +141,47 @@ namespace Common.system
145 141
         /// <summary>
146 142
         /// 截图通用方法 创建人:赵耀 创建时间:2020年8月11日
147 143
         /// </summary>
148
-        /// <param name="ScreenSize">截图的区域,设置new Rectangle(0, 0, 0, 0)为截全屏</param>
149
-        /// <param name="ImageSavePath">图片存储路径,为空或null则保存到临时文件夹</param>
150
-        /// <param name="IsRetImg">是否返回图片</param>
151
-        /// <param name="bitmapimg">图片</param>
144
+        /// <param name="screenSize">截图的区域,设置new Rectangle(0, 0, 0, 0)为截全屏</param>
145
+        /// <param name="imageSavePath">图片存储路径,为空或null则保存到临时文件夹</param>
152 146
         /// <param name="level">压缩等级,0到100,0 最差质量,100 最佳</param>
153 147
         /// <returns></returns>
154
-        public static bool GetScreenshot(Rectangle ScreenSize, string ImageSavePath, long level = -1)
148
+        public static bool GetScreenshot(Rectangle screenSize, string imageSavePath, long level = -1)
155 149
         {
156 150
             try
157 151
             {
158 152
                 System.Drawing.Size bounds = PrimaryScreen.DESKTOP;
159
-                if (string.IsNullOrEmpty(ImageSavePath))
153
+                if (string.IsNullOrEmpty(imageSavePath))
160 154
                 {
161
-                    ImageSavePath = GetTempImagePath();//如果为空则指定临时存储路径
155
+                    imageSavePath = GetTempImagePath(); //如果为空则指定临时存储路径
162 156
                 }
163 157
                 double scaleWidth = (bounds.Width * 1.0) / SystemParameters.PrimaryScreenWidth;
164 158
                 double scaleHeight = (bounds.Height * 1.0) / SystemParameters.PrimaryScreenHeight;
165 159
                 int width = bounds.Width;
166 160
                 int height = bounds.Height;
167
-                if (ScreenSize.Size != new System.Drawing.Size(0, 0))
161
+                if (screenSize.Size != new System.Drawing.Size(0, 0))
168 162
                 {
169
-                    width = (int)(ScreenSize.Size.Width * scaleWidth);
170
-                    height = (int)(ScreenSize.Size.Height * scaleHeight);
163
+                    width = (int)(screenSize.Size.Width * scaleWidth);
164
+                    height = (int)(screenSize.Size.Height * scaleHeight);
171 165
                 }
172
-                int l = (int)(ScreenSize.X * scaleWidth);
173
-                int t = (int)(ScreenSize.Y * scaleHeight);
174
-                if (_Bitmap != null)
166
+                int l = (int)(screenSize.X * scaleWidth);
167
+                int t = (int)(screenSize.Y * scaleHeight);
168
+                if (_bitmap != null)
175 169
                 {
176
-                    _Bitmap.Dispose();
170
+                    _bitmap.Dispose();
177 171
                 }
178
-                _Bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
179
-                using (Graphics g = Graphics.FromImage(_Bitmap))
172
+                _bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
173
+                using (Graphics g = Graphics.FromImage(_bitmap))
180 174
                 {
181
-                    g.CopyFromScreen(l, t, 0, 0, _Bitmap.Size, CopyPixelOperation.SourceCopy);
182
-                    Compress(_Bitmap, ImageSavePath, level);
175
+                    g.CopyFromScreen(
176
+                        l,
177
+                        t,
178
+                        0,
179
+                        0,
180
+                        _bitmap.Size,
181
+                        CopyPixelOperation.SourceCopy
182
+                    );
183
+                    Compress(_bitmap, imageSavePath, level);
183 184
                 }
184
-
185 185
                 GC.Collect();
186 186
                 return true;
187 187
             }
@@ -195,46 +195,60 @@ namespace Common.system
195 195
         /// <summary>
196 196
         /// 截图通用方法 创建人:赵耀 创建时间:2020年8月11日
197 197
         /// </summary>
198
-        /// <param name="ScreenSize">截图的区域,设置new Rectangle(0, 0, 0, 0)为截全屏</param>
199
-        /// <param name="ImageSavePath">图片存储路径,为空或null则保存到临时文件夹</param>
200
-        /// <param name="IsRetImg">是否返回图片</param>
198
+        /// <param name="screenSize">截图的区域,设置new Rectangle(0, 0, 0, 0)为截全屏</param>
199
+        /// <param name="imageSavePath">图片存储路径,为空或null则保存到临时文件夹</param>
200
+        /// <param name="isRetImg">是否返回图片</param>
201 201
         /// <param name="bitmapimg">图片</param>
202 202
         /// <param name="level">压缩等级,0到100,0 最差质量,100 最佳</param>
203 203
         /// <returns></returns>
204
-        public static bool GetScreenshot(Rectangle ScreenSize, string ImageSavePath, bool IsRetImg, out BitmapImage bitmapimg, long level = -1)
204
+        public static bool GetScreenshot
205
+        (
206
+            Rectangle screenSize,
207
+            string imageSavePath,
208
+            bool isRetImg,
209
+            out BitmapImage bitmapimg,
210
+            long level = -1
211
+        )
205 212
         {
206 213
             bitmapimg = null;
207 214
             try
208 215
             {
209 216
                 System.Drawing.Size bounds = PrimaryScreen.DESKTOP;
210
-                if (string.IsNullOrEmpty(ImageSavePath))
217
+                if (string.IsNullOrEmpty(imageSavePath))
211 218
                 {
212
-                    ImageSavePath = GetTempImagePath();//如果为空则指定临时存储路径
219
+                    imageSavePath = GetTempImagePath(); //如果为空则指定临时存储路径
213 220
                 }
214 221
                 double scaleWidth = (bounds.Width * 1.0) / SystemParameters.PrimaryScreenWidth;
215 222
                 double scaleHeight = (bounds.Height * 1.0) / SystemParameters.PrimaryScreenHeight;
216 223
                 int width = bounds.Width;
217 224
                 int height = bounds.Height;
218
-                if (ScreenSize.Size != new System.Drawing.Size(0, 0))
225
+                if (screenSize.Size != new System.Drawing.Size(0, 0))
219 226
                 {
220
-                    width = (int)(ScreenSize.Size.Width * scaleWidth);
221
-                    height = (int)(ScreenSize.Size.Height * scaleHeight);
227
+                    width = (int)(screenSize.Size.Width * scaleWidth);
228
+                    height = (int)(screenSize.Size.Height * scaleHeight);
222 229
                 }
223
-                int l = (int)(ScreenSize.X * scaleWidth);
224
-                int t = (int)(ScreenSize.Y * scaleHeight);
225
-                if (_Bitmap != null)
230
+                int l = (int)(screenSize.X * scaleWidth);
231
+                int t = (int)(screenSize.Y * scaleHeight);
232
+                if (_bitmap != null)
226 233
                 {
227
-                    _Bitmap.Dispose();
234
+                    _bitmap.Dispose();
228 235
                 }
229
-                _Bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
230
-                using (Graphics g = Graphics.FromImage(_Bitmap))
236
+                _bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
237
+                using (Graphics g = Graphics.FromImage(_bitmap))
231 238
                 {
232
-                    g.CopyFromScreen(l, t, 0, 0, _Bitmap.Size, CopyPixelOperation.SourceCopy);
233
-                    Compress(_Bitmap, ImageSavePath, level);
239
+                    g.CopyFromScreen(
240
+                        l,
241
+                        t,
242
+                        0,
243
+                        0,
244
+                        _bitmap.Size,
245
+                        CopyPixelOperation.SourceCopy
246
+                    );
247
+                    Compress(_bitmap, imageSavePath, level);
234 248
                 }
235
-                if (IsRetImg)
249
+                if (isRetImg)
236 250
                 {
237
-                    Uri uri = new Uri(ImageSavePath, UriKind.Absolute);
251
+                    Uri uri = new Uri(imageSavePath, UriKind.Absolute);
238 252
                     bitmapimg = new BitmapImage(uri);
239 253
                 }
240 254
                 GC.Collect();
@@ -253,12 +267,20 @@ namespace Common.system
253 267
         /// <returns></returns>
254 268
         public static string GetTempImagePath()
255 269
         {
256
-            TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
257
-
258
-            string TempPath = FileToolsCommon.GetFileAbsolutePath("/temp/Screenshot/");
259
-            FileToolsCommon.CreateDirectory(TempPath);
260
-            TempPath += Convert.ToInt64(ts.TotalMilliseconds).ToString() + ".jpg";
261
-            return TempPath;
270
+            TimeSpan ts = DateTime.Now -
271
+            new DateTime(
272
+                1970,
273
+                1,
274
+                1,
275
+                0,
276
+                0,
277
+                0,
278
+                0
279
+            );
280
+            string tempPath = FileToolsCommon.GetFileAbsolutePath("/temp/Screenshot/");
281
+            FileToolsCommon.CreateDirectory(tempPath);
282
+            tempPath += Convert.ToInt64(ts.TotalMilliseconds).ToString() + ".jpg";
283
+            return tempPath;
262 284
         }
263 285
 
264 286
         #endregion 截图统一方法
@@ -275,8 +297,8 @@ namespace Common.system
275 297
         {
276 298
             if (level <= -1)
277 299
             {
278
-                int ImageCompressionLevel = int.Parse(FileToolsCommon.GetConfigValue("ImageCompressionLevel"));
279
-                level = ImageCompressionLevel;
300
+                int imageCompressionLevel = int.Parse(FileToolsCommon.GetConfigValue("ImageCompressionLevel"));
301
+                level = imageCompressionLevel;
280 302
             }
281 303
             Stream s = new FileStream(destFile, FileMode.Create);
282 304
             Compress(srcBitMap, s, level);
@@ -291,19 +313,11 @@ namespace Common.system
291 313
         /// <param name="level">压缩等级,0到100,0 最差质量,100 最佳</param>
292 314
         public static void Compress(Bitmap srcBitmap, Stream destStream, long level)
293 315
         {
294
-            ImageCodecInfo myImageCodecInfo;
295
-            System.Drawing.Imaging.Encoder myEncoder;
296
-            EncoderParameter myEncoderParameter;
297
-            EncoderParameters myEncoderParameters;
298
-
299 316
             //获取表示jpeg编解码器的imagecodecinfo对象
300
-            myImageCodecInfo = GetEncoderInfo("image/jpeg");
301
-
302
-            myEncoder = System.Drawing.Imaging.Encoder.Quality;
303
-
304
-            myEncoderParameters = new EncoderParameters(1);
305
-
306
-            myEncoderParameter = new EncoderParameter(myEncoder, level);
317
+            ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/jpeg");
318
+            System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
319
+            EncoderParameters myEncoderParameters = new EncoderParameters(1);
320
+            EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, level);
307 321
             myEncoderParameters.Param[0] = myEncoderParameter;
308 322
             srcBitmap.Save(destStream, myImageCodecInfo, myEncoderParameters);
309 323
         }
@@ -331,13 +345,18 @@ namespace Common.system
331 345
         /// <summary>
332 346
         /// 压缩图片 -测试方法 待完善 暂无用
333 347
         /// </summary>
334
-        /// <param name="_bitmap">原图片</param>
348
+        /// <param name="mbitmap">原图片</param>
335 349
         /// <param name="dFile">压缩后保存图片地址</param>
336 350
         /// <param name="flag">压缩质量(数字越小压缩率越高)1-100</param>
337 351
         /// <param name="size">压缩后图片的最大大小</param>
338
-        /// <param name="sfsc">是否是第一次调用</param>
339 352
         /// <returns></returns>
340
-        public static bool CompressImage(Bitmap _bitmap, string dFile, int flag = 90, int size = 300)
353
+        public static bool CompressImage
354
+        (
355
+            Bitmap mbitmap,
356
+            string dFile,
357
+            int flag = 90,
358
+            int size = 300
359
+        )
341 360
         {
342 361
             ////如果是第一次调用,原始图像的大小小于要压缩的大小,则直接复制文件,并且返回true
343 362
             //FileInfo firstFileInfo = new FileInfo(sFile);
@@ -347,86 +366,88 @@ namespace Common.system
347 366
             //    return true;
348 367
             //}
349 368
             //Image iSource = Image.FromFile(sFile);
350
-            Image iSource = _bitmap;
369
+            Image iSource = mbitmap;
351 370
             ImageFormat tFormat = iSource.RawFormat;
352 371
             int dHeight = iSource.Height / 2;
353 372
             int dWidth = iSource.Width / 2;
354 373
             int sW, sH;
355 374
             //按比例缩放
356
-            System.Drawing.Size tem_size = new System.Drawing.Size(iSource.Width, iSource.Height);
357
-            if (tem_size.Width > dHeight || tem_size.Width > dWidth)
375
+            System.Drawing.Size temSize = new System.Drawing.Size(iSource.Width, iSource.Height);
376
+            if (temSize.Width > dHeight || temSize.Width > dWidth)
358 377
             {
359
-                if ((tem_size.Width * dHeight) > (tem_size.Width * dWidth))
378
+                if ((temSize.Width * dHeight) > (temSize.Width * dWidth))
360 379
                 {
361 380
                     sW = dWidth;
362
-                    sH = (dWidth * tem_size.Height) / tem_size.Width;
381
+                    sH = (dWidth * temSize.Height) / temSize.Width;
363 382
                 }
364 383
                 else
365 384
                 {
366 385
                     sH = dHeight;
367
-                    sW = (tem_size.Width * dHeight) / tem_size.Height;
386
+                    sW = (temSize.Width * dHeight) / temSize.Height;
368 387
                 }
369 388
             }
370 389
             else
371 390
             {
372
-                sW = tem_size.Width;
373
-                sH = tem_size.Height;
391
+                sW = temSize.Width;
392
+                sH = temSize.Height;
374 393
             }
375
-
376 394
             Bitmap ob = new Bitmap(dWidth, dHeight);
377 395
             Graphics g = Graphics.FromImage(ob);
378
-
379 396
             g.Clear(System.Drawing.Color.WhiteSmoke);
380 397
             g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
381 398
             g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
382 399
             g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
383
-
384
-            g.DrawImage(iSource, new Rectangle((dWidth - sW) / 2, (dHeight - sH) / 2, sW, sH), 0, 0, iSource.Width, iSource.Height, GraphicsUnit.Pixel);
385
-
400
+            g.DrawImage(
401
+                iSource,
402
+                new Rectangle(
403
+                    (dWidth - sW) / 2,
404
+                    (dHeight - sH) / 2,
405
+                    sW,
406
+                    sH
407
+                ),
408
+                0,
409
+                0,
410
+                iSource.Width,
411
+                iSource.Height,
412
+                GraphicsUnit.Pixel
413
+            );
386 414
             g.Dispose();
387 415
 
388 416
             //以下代码为保存图片时,设置压缩质量
389 417
             EncoderParameters ep = new EncoderParameters();
390 418
             long[] qy = new long[1];
391
-            qy[0] = flag;//设置压缩的比例1-100
419
+            qy[0] = flag; //设置压缩的比例1-100
392 420
             EncoderParameter eParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qy);
393 421
             ep.Param[0] = eParam;
394
-
395 422
             try
396 423
             {
397
-                ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
398
-                ImageCodecInfo jpegICIinfo = null;
399
-                for (int x = 0; x < arrayICI.Length; x++)
424
+                ImageCodecInfo[] arrayIci = ImageCodecInfo.GetImageEncoders();
425
+                ImageCodecInfo jpegIcIinfo = null;
426
+                for (int x = 0; x < arrayIci.Length; x++)
400 427
                 {
401
-                    if (arrayICI[x].FormatDescription.Equals("JPEG"))
428
+                    if (arrayIci[x].FormatDescription.Equals("JPEG"))
402 429
                     {
403
-                        jpegICIinfo = arrayICI[x];
430
+                        jpegIcIinfo = arrayIci[x];
404 431
                         break;
405 432
                     }
406 433
                 }
407
-                if (jpegICIinfo != null)
434
+                if (jpegIcIinfo != null)
408 435
                 {
409 436
                     if (flag > 0)
410 437
                     {
411
-                        ob.Save(dFile, jpegICIinfo, ep);//dFile是压缩后的新路径
438
+                        ob.Save(dFile, jpegIcIinfo, ep); //dFile是压缩后的新路径
412 439
                         FileInfo fi = new FileInfo(dFile);
413 440
                         if (fi.Length > 1024 * size)
414 441
                         {
415 442
                             flag -= 10;
416
-                            CompressImage(_bitmap, dFile, flag, size);
443
+                            CompressImage(
444
+                                mbitmap,
445
+                                dFile,
446
+                                flag,
447
+                                size
448
+                            );
417 449
                         }
418 450
                     }
419
-                    //ob.Save(dFile, jpegICIinfo, ep);
420
-                    //FileInfo fi = new FileInfo(dFile);
421
-                    //bool IsAgain = false;
422
-                    //if (fi.Length > 1024 * size)
423
-                    //{
424
-                    //    fi.CopyTo(dFile + fi.Length);
425
-                    //    fi.Delete();
426
-                    //    Bitmap newbitmap = ReadImageFile(dFile + fi.Length);
427
-                    //    CompressImage(newbitmap, dFile, flag, size);
428
-                    //    FileToolsCommon.DeleteFile(dFile + fi.Length);
429
-                    //}
430 451
                 }
431 452
                 else
432 453
                 {
@@ -454,30 +475,37 @@ namespace Common.system
454 475
         /// </summary>
455 476
         /// <param name="ui">需要截图的UI控件</param>
456 477
         /// <param name="filePathName">图片保存地址 命名 1.png</param>
457
-        /// <param name="ImgWidth">转换后高</param>
458
-        /// <param name="ImgHeight">转换后高</param>
459
-        public static void SaveUI(FrameworkElement ui, string filePathName, int ImgWidth, int ImgHeight)
478
+        /// <param name="imgWidth">转换后高</param>
479
+        /// <param name="imgHeight">转换后高</param>
480
+        public static void SaveUi
481
+        (
482
+            FrameworkElement ui,
483
+            string filePathName,
484
+            int imgWidth,
485
+            int imgHeight
486
+        )
460 487
         {
461
-            Console.WriteLine("截图的路径为:" + filePathName);
488
+            Console.WriteLine(@"截图的路径为:" + filePathName);
462 489
             try
463 490
             {
464 491
                 RenderTargetBitmap bmp = new RenderTargetBitmap(
465
-                       (int)ui.ActualWidth,
466
-                       (int)ui.ActualHeight,
467
-                       1 / 96, 1 / 96,
468
-                       PixelFormats.Default
469
-                   );
492
+                    (int)ui.ActualWidth,
493
+                    (int)ui.ActualHeight,
494
+                    96,
495
+                    96,
496
+                    PixelFormats.Default
497
+                );
470 498
                 bmp.Render(ui);
471 499
                 BitmapEncoder encoder = new PngBitmapEncoder();
472 500
                 encoder.Frames.Add(BitmapFrame.Create(bmp));
473
-                if (ImgWidth > 0)
501
+                if (imgWidth > 0)
474 502
                 {
475 503
                     MemoryStream memoryStream = new MemoryStream();
476 504
                     encoder.Save(memoryStream);
477 505
                     Bitmap bit = new Bitmap(memoryStream, true);
478
-                    Bitmap Img = new Bitmap(bit, ImgWidth, ImgHeight);
479
-                    Img.Save(filePathName);
480
-                    Img.Dispose();
506
+                    Bitmap img = new Bitmap(bit, imgWidth, imgHeight);
507
+                    img.Save(filePathName);
508
+                    img.Dispose();
481 509
                     bit.Dispose();
482 510
                     memoryStream.Dispose();
483 511
                 }
@@ -495,10 +523,16 @@ namespace Common.system
495 523
             }
496 524
         }
497 525
 
498
-        public static void SaveUI2(FrameworkElement frameworkElement, string filePathName)
526
+        public static void SaveUi2(FrameworkElement frameworkElement, string filePathName)
499 527
         {
500 528
             System.IO.FileStream fs = new System.IO.FileStream(filePathName, System.IO.FileMode.Create);
501
-            RenderTargetBitmap bmp = new RenderTargetBitmap((int)frameworkElement.ActualWidth, (int)frameworkElement.ActualHeight, 1 / 96, 1 / 96, PixelFormats.Default);
529
+            RenderTargetBitmap bmp = new RenderTargetBitmap(
530
+                (int)frameworkElement.ActualWidth,
531
+                (int)frameworkElement.ActualHeight,
532
+                96,
533
+                96,
534
+                PixelFormats.Default
535
+            );
502 536
             bmp.Render(frameworkElement);
503 537
             BitmapEncoder encoder = new PngBitmapEncoder();
504 538
             encoder.Frames.Add(BitmapFrame.Create(bmp));
@@ -506,22 +540,21 @@ namespace Common.system
506 540
             fs.Close();
507 541
         }
508 542
 
509
-        public static Bitmap SaveUI2Bitmap(FrameworkElement frameworkElement, int width, int height)
543
+        public static Bitmap SaveUi2Bitmap(FrameworkElement frameworkElement, int width, int height)
510 544
         {
511 545
             using (MemoryStream outStream = new MemoryStream())
512 546
             {
513 547
                 RenderTargetBitmap bmp = new RenderTargetBitmap(
514
-                        (int)frameworkElement.ActualWidth,
515
-                        (int)frameworkElement.ActualHeight,
516
-                        1 / 96,
517
-                        1 / 96,
518
-                        PixelFormats.Default
519
-                    );
548
+                    (int)frameworkElement.ActualWidth,
549
+                    (int)frameworkElement.ActualHeight,
550
+                    96,
551
+                    96,
552
+                    PixelFormats.Default
553
+                );
520 554
                 bmp.Render(frameworkElement);
521 555
                 BitmapEncoder enc = new PngBitmapEncoder();
522 556
                 enc.Frames.Add(BitmapFrame.Create(bmp));
523 557
                 enc.Save(outStream);
524
-
525 558
                 System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream);
526 559
                 return new Bitmap(bitmap, width, height);
527 560
             }
@@ -531,25 +564,38 @@ namespace Common.system
531 564
         /// 截图转换成bitmap
532 565
         /// </summary>
533 566
         /// <param name="element"></param>
567
+        /// <param name="filePathName"></param>
534 568
         /// <param name="width">默认控件宽度</param>
535 569
         /// <param name="height">默认控件高度</param>
536 570
         /// <param name="x">默认0</param>
537 571
         /// <param name="y">默认0</param>
538 572
         /// <returns></returns>
539
-        public static Bitmap ToBitmap(FrameworkElement element, string filePathName, int width = 0, int height = 0, int x = 0, int y = 0)
573
+        public static Bitmap ToBitmap
574
+        (
575
+            FrameworkElement element,
576
+            string filePathName,
577
+            int width = 0,
578
+            int height = 0,
579
+            int x = 0,
580
+            int y = 0
581
+        )
540 582
         {
541 583
             if (width == 0) width = (int)element.ActualWidth;
542 584
             if (height == 0) height = (int)element.ActualHeight;
543
-
544
-            var rtb = new RenderTargetBitmap(width, height, x, y, System.Windows.Media.PixelFormats.Default);
585
+            var rtb = new RenderTargetBitmap(
586
+                width,
587
+                height,
588
+                x,
589
+                y,
590
+                System.Windows.Media.PixelFormats.Default
591
+            );
545 592
             rtb.Render(element);
546
-            var bit = BitmapSourceToBitmap(rtb);
593
+            Bitmap bit = BitmapSourceToBitmap(rtb);
547 594
 
548 595
             //测试代码
549 596
             DirectoryInfo d = new DirectoryInfo(System.IO.Path.Combine(Directory.GetCurrentDirectory(), "Cache"));
550 597
             if (!d.Exists) d.Create();
551 598
             bit.Save(System.IO.Path.Combine(d.FullName, "控件截图.png"));
552
-
553 599
             return bit;
554 600
         }
555 601
 
@@ -567,6 +613,8 @@ namespace Common.system
567 613
         /// Convert BitmapSource to Bitmap
568 614
         /// </summary>
569 615
         /// <param name="source"></param>
616
+        /// <param name="width"></param>
617
+        /// <param name="height"></param>
570 618
         /// <returns></returns>
571 619
         public static Bitmap BitmapSourceToBitmap(BitmapSource source, int width, int height)
572 620
         {
@@ -578,16 +626,27 @@ namespace Common.system
578 626
                 switch (source.Format.ToString())
579 627
                 {
580 628
                     case "Rgb24":
581
-                    case "Bgr24": format = System.Drawing.Imaging.PixelFormat.Format24bppRgb; break;
582
-                    case "Bgra32": format = System.Drawing.Imaging.PixelFormat.Format32bppPArgb; break;
583
-                    case "Bgr32": format = System.Drawing.Imaging.PixelFormat.Format32bppRgb; break;
584
-                    case "Pbgra32": format = System.Drawing.Imaging.PixelFormat.Format32bppArgb; break;
629
+                    case "Bgr24":
630
+                        format = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
631
+                        break;
632
+                    case "Bgra32":
633
+                        format = System.Drawing.Imaging.PixelFormat.Format32bppPArgb;
634
+                        break;
635
+                    case "Bgr32":
636
+                        format = System.Drawing.Imaging.PixelFormat.Format32bppRgb;
637
+                        break;
638
+                    case "Pbgra32":
639
+                        format = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
640
+                        break;
585 641
                 }
586 642
                 bmp = new Bitmap(width, height, format);
587
-                BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size),
588
-                    ImageLockMode.WriteOnly,
589
-                    format);
590
-                source.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
643
+                BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size), ImageLockMode.WriteOnly, format);
644
+                source.CopyPixels(
645
+                    Int32Rect.Empty,
646
+                    data.Scan0,
647
+                    data.Height * data.Stride,
648
+                    data.Stride
649
+                );
591 650
                 bmp.UnlockBits(data);
592 651
             }
593 652
             catch
@@ -598,7 +657,6 @@ namespace Common.system
598 657
                     bmp = null;
599 658
                 }
600 659
             }
601
-
602 660
             return bmp;
603 661
         }
604 662
 
@@ -609,7 +667,6 @@ namespace Common.system
609 667
         /// <summary>
610 668
         /// 裁剪图片(去掉白边)
611 669
         /// </summary>
612
-        /// <param name="FilePath"></param>
613 670
         public static Bitmap CutImageWhitePart(Bitmap bmp)
614 671
         {
615 672
             //Bitmap bmp = new Bitmap(FilePath);
@@ -617,10 +674,10 @@ namespace Common.system
617 674
             int top = 0, left = 0, right = bmp.Width, bottom = bmp.Height;
618 675
 
619 676
             //寻找最上面的标线,从左(0)到右,从上(0)到下
620
-            for (int i = 0; i < bmp.Height; i++)//行
677
+            for (int i = 0; i < bmp.Height; i++) //行
621 678
             {
622 679
                 bool find = false;
623
-                for (int j = 0; j < bmp.Width; j++)//列
680
+                for (int j = 0; j < bmp.Width; j++) //列
624 681
                 {
625 682
                     System.Drawing.Color c = bmp.GetPixel(j, i);
626 683
                     if (!IsWhite(c))
@@ -636,10 +693,10 @@ namespace Common.system
636 693
                 }
637 694
             }
638 695
             //寻找最左边的标线,从上(top位)到下,从左到右
639
-            for (int i = 0; i < bmp.Width; i++)//列
696
+            for (int i = 0; i < bmp.Width; i++) //列
640 697
             {
641 698
                 bool find = false;
642
-                for (int j = top; j < bmp.Height; j++)//行
699
+                for (int j = top; j < bmp.Height; j++) //行
643 700
                 {
644 701
                     System.Drawing.Color c = bmp.GetPixel(i, j);
645 702
                     if (!IsWhite(c))
@@ -655,10 +712,10 @@ namespace Common.system
655 712
                 }
656 713
             }
657 714
             //寻找最下边标线,从下到上,从左到右
658
-            for (int i = bmp.Height - 1; i >= 0; i--)//行
715
+            for (int i = bmp.Height - 1; i >= 0; i--) //行
659 716
             {
660 717
                 bool find = false;
661
-                for (int j = left; j < bmp.Width; j++)//列
718
+                for (int j = left; j < bmp.Width; j++) //列
662 719
                 {
663 720
                     System.Drawing.Color c = bmp.GetPixel(j, i);
664 721
                     if (!IsWhite(c))
@@ -674,10 +731,10 @@ namespace Common.system
674 731
                 }
675 732
             }
676 733
             //寻找最右边的标线,从上到下,从右往左
677
-            for (int i = bmp.Width - 1; i >= 0; i--)//列
734
+            for (int i = bmp.Width - 1; i >= 0; i--) //列
678 735
             {
679 736
                 bool find = false;
680
-                for (int j = 0; j <= bottom; j++)//行
737
+                for (int j = 0; j <= bottom; j++) //行
681 738
                 {
682 739
                     System.Drawing.Color c = bmp.GetPixel(i, j);
683 740
                     if (!IsWhite(c))
@@ -692,11 +749,15 @@ namespace Common.system
692 749
                     break;
693 750
                 }
694 751
             }
695
-
696
-            if (right - left <= 0)//zxyceshi
752
+            if (right - left <= 0) //zxyceshi
697 753
             {
698 754
                 //克隆位图对象的一部分。
699
-                System.Drawing.Rectangle cloneRect = new System.Drawing.Rectangle(left, top, 1, bottom - top);
755
+                System.Drawing.Rectangle cloneRect = new System.Drawing.Rectangle(
756
+                    left,
757
+                    top,
758
+                    1,
759
+                    bottom - top
760
+                );
700 761
                 Bitmap cloneBitmap = bmp.Clone(cloneRect, bmp.PixelFormat);
701 762
                 bmp.Dispose();
702 763
                 //cloneBitmap.Save(@"d:\123.png", ImageFormat.Png);
@@ -705,7 +766,12 @@ namespace Common.system
705 766
             else
706 767
             {
707 768
                 //克隆位图对象的一部分。
708
-                System.Drawing.Rectangle cloneRect = new System.Drawing.Rectangle(left, top, right - left, bottom - top);
769
+                System.Drawing.Rectangle cloneRect = new System.Drawing.Rectangle(
770
+                    left,
771
+                    top,
772
+                    right - left,
773
+                    bottom - top
774
+                );
709 775
                 Bitmap cloneBitmap = bmp.Clone(cloneRect, bmp.PixelFormat);
710 776
                 bmp.Dispose();
711 777
                 //cloneBitmap.Save(@"d:\123.png", ImageFormat.Png);
@@ -723,7 +789,6 @@ namespace Common.system
723 789
             {
724 790
                 return true;
725 791
             }
726
-
727 792
             return false;
728 793
         }
729 794
 
@@ -733,6 +798,7 @@ namespace Common.system
733 798
     public class SaveImageModel
734 799
     {
735 800
         public string FilePath { get; set; }
801
+
736 802
         public BitmapEncoder encoder { get; set; }
737 803
         //public RenderTargetBitmap bmp { get; set; }
738 804
     }
@@ -745,4 +811,4 @@ namespace Common.system
745 811
         public string filePathName { get; set; }
746 812
         public RenderTargetBitmap bmp { get; set; }
747 813
     }
748
-}
814
+}

+ 153
- 186
XHWK.WKTool/Utils/ImageOperationUtil.cs View File

@@ -13,38 +13,40 @@ namespace XHWK.WKTool.Utils
13 13
     {
14 14
         #region 图片拉伸移动
15 15
 
16
-        private System.Windows.Point initialPoint;
17
-
18
-        private Thumb RectLeftUp;
19
-        private Thumb RectRightUp;
20
-        private Thumb RectLeftDown;
21
-        private Thumb RectRightDown;
22
-        private System.Windows.Shapes.Rectangle RectImgBorder;
23
-        private System.Windows.Controls.Image imgCanvas;
24
-        private Grid GridM;
25
-        private bool mouseDown = false;
26
-
27
-        public void setMouseDown(bool mouseDown) {
28
-            this.mouseDown = mouseDown;
16
+        private System.Windows.Point _initialPoint;
17
+
18
+        private Thumb _rectLeftUp;
19
+        private Thumb _rectRightUp;
20
+        private Thumb _rectLeftDown;
21
+        private Thumb _rectRightDown;
22
+        private System.Windows.Shapes.Rectangle _rectImgBorder;
23
+        private System.Windows.Controls.Image _imgCanvas;
24
+        private Grid _gridM;
25
+        private bool _mouseDown;
26
+
27
+        public void SetMouseDown(bool mouseDown)
28
+        {
29
+            this._mouseDown = mouseDown;
29 30
         }
30 31
 
31
-        public ImageOperationUtil(
32
-             Thumb RectLeftUp,
33
-             Thumb RectRightUp,
34
-             Thumb RectLeftDown,
35
-             Thumb RectRightDown,
36
-             System.Windows.Shapes.Rectangle RectImgBorder,
37
-             System.Windows.Controls.Image imgCanvas,
38
-             Grid GridM
39
-            )
32
+        public ImageOperationUtil
33
+        (
34
+            Thumb rectLeftUp,
35
+            Thumb rectRightUp,
36
+            Thumb rectLeftDown,
37
+            Thumb rectRightDown,
38
+            System.Windows.Shapes.Rectangle rectImgBorder,
39
+            System.Windows.Controls.Image imgCanvas,
40
+            Grid gridM
41
+        )
40 42
         {
41
-            this.RectLeftUp = RectLeftUp;
42
-            this.RectRightUp = RectRightUp;
43
-            this.RectLeftDown = RectLeftDown;
44
-            this.RectRightDown = RectRightDown;
45
-            this.RectImgBorder = RectImgBorder;
46
-            this.imgCanvas = imgCanvas;
47
-            this.GridM = GridM;
43
+            this._rectLeftUp = rectLeftUp;
44
+            this._rectRightUp = rectRightUp;
45
+            this._rectLeftDown = rectLeftDown;
46
+            this._rectRightDown = rectRightDown;
47
+            this._rectImgBorder = rectImgBorder;
48
+            this._imgCanvas = imgCanvas;
49
+            this._gridM = gridM;
48 50
         }
49 51
 
50 52
         /// <summary>
@@ -52,21 +54,21 @@ namespace XHWK.WKTool.Utils
52 54
         /// </summary>
53 55
         public void HideAngleBorder()
54 56
         {
55
-            RectLeftUp.Visibility = Visibility.Hidden;
56
-            RectRightUp.Visibility = Visibility.Hidden;
57
-            RectLeftDown.Visibility = Visibility.Hidden;
58
-            RectRightDown.Visibility = Visibility.Hidden;
59
-            RectImgBorder.Visibility = Visibility.Hidden;
57
+            _rectLeftUp.Visibility = Visibility.Hidden;
58
+            _rectRightUp.Visibility = Visibility.Hidden;
59
+            _rectLeftDown.Visibility = Visibility.Hidden;
60
+            _rectRightDown.Visibility = Visibility.Hidden;
61
+            _rectImgBorder.Visibility = Visibility.Hidden;
60 62
         }
61 63
 
62 64
         private void ShowAngleBorder()
63 65
         {
64 66
             PointLocation();
65
-            RectLeftUp.Visibility = Visibility.Visible;
66
-            RectRightUp.Visibility = Visibility.Visible;
67
-            RectLeftDown.Visibility = Visibility.Visible;
68
-            RectRightDown.Visibility = Visibility.Visible;
69
-            RectImgBorder.Visibility = Visibility.Visible;
67
+            _rectLeftUp.Visibility = Visibility.Visible;
68
+            _rectRightUp.Visibility = Visibility.Visible;
69
+            _rectLeftDown.Visibility = Visibility.Visible;
70
+            _rectRightDown.Visibility = Visibility.Visible;
71
+            _rectImgBorder.Visibility = Visibility.Visible;
70 72
         }
71 73
 
72 74
         /// <summary>
@@ -74,84 +76,79 @@ namespace XHWK.WKTool.Utils
74 76
         /// </summary>
75 77
         private void PointLocation()
76 78
         {
77
-            RectImgBorder.Width = imgCanvas.ActualWidth + 10.0;
78
-            RectImgBorder.Height = imgCanvas.ActualHeight + 10.0;
79
-            RectImgBorder.Margin = new Thickness(imgCanvas.Margin.Left - 5.0, imgCanvas.Margin.Top - 5.0, 0, 0);
80
-
81
-            Canvas.SetLeft(RectLeftUp, imgCanvas.Margin.Left - 10.0);
82
-            Canvas.SetTop(RectLeftUp, imgCanvas.Margin.Top - 10.0);
83
-
84
-            Canvas.SetLeft(RectRightUp, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
85
-            Canvas.SetTop(RectRightUp, imgCanvas.Margin.Top - 10.0);
86
-
87
-            Canvas.SetLeft(RectLeftDown, imgCanvas.Margin.Left - 10.0);
88
-            Canvas.SetTop(RectLeftDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
89
-
90
-            Canvas.SetLeft(RectRightDown, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
91
-            Canvas.SetTop(RectRightDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
79
+            _rectImgBorder.Width = _imgCanvas.ActualWidth + 10.0;
80
+            _rectImgBorder.Height = _imgCanvas.ActualHeight + 10.0;
81
+            _rectImgBorder.Margin = new Thickness(
82
+                _imgCanvas.Margin.Left - 5.0,
83
+                _imgCanvas.Margin.Top - 5.0,
84
+                0,
85
+                0
86
+            );
87
+            Canvas.SetLeft(_rectLeftUp, _imgCanvas.Margin.Left - 10.0);
88
+            Canvas.SetTop(_rectLeftUp, _imgCanvas.Margin.Top - 10.0);
89
+            Canvas.SetLeft(_rectRightUp, _imgCanvas.Margin.Left + _imgCanvas.ActualWidth - 10.0);
90
+            Canvas.SetTop(_rectRightUp, _imgCanvas.Margin.Top - 10.0);
91
+            Canvas.SetLeft(_rectLeftDown, _imgCanvas.Margin.Left - 10.0);
92
+            Canvas.SetTop(_rectLeftDown, _imgCanvas.Margin.Top + _imgCanvas.ActualHeight - 10.0);
93
+            Canvas.SetLeft(_rectRightDown, _imgCanvas.Margin.Left + _imgCanvas.ActualWidth - 10.0);
94
+            Canvas.SetTop(_rectRightDown, _imgCanvas.Margin.Top + _imgCanvas.ActualHeight - 10.0);
92 95
         }
93 96
 
94 97
         public void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
95 98
         {
96
-            System.Windows.Point point = e.GetPosition(imgCanvas);
97
-            initialPoint = point;
98
-
99
+            System.Windows.Point point = e.GetPosition(_imgCanvas);
100
+            _initialPoint = point;
99 101
             HideAngleBorder();
100 102
         }
101 103
 
102 104
         public void imgCanvas_MouseMove(object sender, MouseEventArgs e)
103 105
         {
104
-            if (e.LeftButton == MouseButtonState.Pressed && mouseDown)
106
+            if (e.LeftButton == MouseButtonState.Pressed && _mouseDown)
105 107
             {
106
-                System.Windows.Point point = e.GetPosition(imgCanvas);
107
-                imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left + (point.X - initialPoint.X), imgCanvas.Margin.Top + (point.Y - initialPoint.Y), 0, 0);
108
-                App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
109
-                {
110
-                    X = imgCanvas.Margin.Left,
111
-                    Y = imgCanvas.Margin.Top
112
-                };
113
-                App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
114
-                {
115
-                    CenterX = imgCanvas.ActualWidth,
116
-                    CenterY = imgCanvas.ActualHeight
117
-                };
108
+                System.Windows.Point point = e.GetPosition(_imgCanvas);
109
+                _imgCanvas.Margin = new Thickness(
110
+                    _imgCanvas.Margin.Left + (point.X - _initialPoint.X),
111
+                    _imgCanvas.Margin.Top + (point.Y - _initialPoint.Y),
112
+                    0,
113
+                    0
114
+                );
115
+                App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform { X = _imgCanvas.Margin.Left, Y = _imgCanvas.Margin.Top };
116
+                App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes = new ScaleTransform { CenterX = _imgCanvas.ActualWidth, CenterY = _imgCanvas.ActualHeight };
118 117
                 App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
119 118
             }
120 119
         }
121 120
 
122 121
         public void imgCanvas_MouseUp()
123 122
         {
124
-            if (mouseDown)
123
+            if (_mouseDown)
125 124
             {
126 125
                 ShowAngleBorder();
127 126
             }
128 127
         }
129 128
 
130
-        private PointF imgRightDown;
129
+        private PointF _imgRightDown;
131 130
 
132 131
         /// <summary>
133 132
         /// 设置控件最上层
134 133
         /// </summary>
135 134
         /// <param name="element">
136 135
         /// </param>
137
-        public void BringToFront(Thumb element)//图片置于最顶层显示
136
+        public void BringToFront(Thumb element) //图片置于最顶层显示
138 137
         {
139 138
             if (element == null)
140 139
             {
141 140
                 return;
142 141
             }
143
-
144 142
             Canvas parent = element.Parent as Canvas;
145 143
             if (parent == null)
146 144
             {
147 145
                 return;
148 146
             }
149
-
150
-            int maxZ = parent.Children.OfType<UIElement>()//linq语句,取Zindex的最大值
151
-              .Where(x => x != element)
152
-              .Select(x => Canvas.GetZIndex(x))
153
-              .Max();
154
-            Canvas.SetZIndex(element, maxZ + 1);
147
+            int maxZ = parent.Children.OfType<UIElement>() //linq语句,取Zindex的最大值
148
+                .Where(x => x != element)
149
+                .Select(x => Panel.GetZIndex(x))
150
+                .Max();
151
+            Panel.SetZIndex(element, maxZ + 1);
155 152
         }
156 153
 
157 154
         public void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
@@ -160,28 +157,21 @@ namespace XHWK.WKTool.Utils
160 157
             {
161 158
                 Thumb thu = (Thumb)sender;
162 159
                 BringToFront(thu);
163
-
164
-                imgRightDown = new System.Drawing.PointF((float)(imgCanvas.Margin.Left + imgCanvas.ActualWidth), (float)(imgCanvas.Margin.Top + imgCanvas.ActualHeight));
160
+                _imgRightDown = new System.Drawing.PointF((float)(_imgCanvas.Margin.Left + _imgCanvas.ActualWidth), (float)(_imgCanvas.Margin.Top + _imgCanvas.ActualHeight));
165 161
                 HideAngleBorder();
166 162
                 switch (thu.Name)
167 163
                 {
168 164
                     case "RectLeftUp":
169
-                        RectLeftUp.Visibility = Visibility.Visible;
165
+                        _rectLeftUp.Visibility = Visibility.Visible;
170 166
                         break;
171
-
172 167
                     case "RectRightUp":
173
-                        RectRightUp.Visibility = Visibility.Visible;
168
+                        _rectRightUp.Visibility = Visibility.Visible;
174 169
                         break;
175
-
176 170
                     case "RectLeftDown":
177
-                        RectLeftDown.Visibility = Visibility.Visible;
171
+                        _rectLeftDown.Visibility = Visibility.Visible;
178 172
                         break;
179
-
180 173
                     case "RectRightDown":
181
-                        RectRightDown.Visibility = Visibility.Visible;
182
-                        break;
183
-
184
-                    default:
174
+                        _rectRightDown.Visibility = Visibility.Visible;
185 175
                         break;
186 176
                 }
187 177
             }
@@ -195,134 +185,131 @@ namespace XHWK.WKTool.Utils
195 185
         {
196 186
             try
197 187
             {
198
-                if (mouseDown)
188
+                if (_mouseDown)
199 189
                 {
200 190
                     Thumb thu = (Thumb)sender;
201
-
202
-                    #region 判断是否超出 暂无
203
-
204
-                    double plul = Canvas.GetLeft(RectLeftUp);
205
-                    double plut = Canvas.GetTop(RectLeftUp);
206
-                    double prdl = Canvas.GetLeft(RectRightDown);
207
-                    double prdt = Canvas.GetTop(RectRightDown);
208
-
209
-                    #endregion 判断是否超出 暂无
210
-
211
-                    double imgW = 0;
212
-                    double imgH = 0;
213
-                    double imgX = 0;
214
-                    double imgY = 0;
191
+                    double imgW;
192
+                    double imgH;
193
+                    double imgX;
194
+                    double imgY;
215 195
                     switch (thu.Name)
216 196
                     {
217 197
                         case "RectLeftUp":
218 198
 
219 199
                             #region 左上
220 200
 
221
-                            imgW = imgRightDown.X - (Mouse.GetPosition(GridM).X);
222
-                            imgH = imgRightDown.Y - (Mouse.GetPosition(GridM).Y);
223
-                            imgX = 0;
224
-                            imgY = 0;
201
+                            imgW = _imgRightDown.X - (Mouse.GetPosition(_gridM).X);
202
+                            imgH = _imgRightDown.Y - (Mouse.GetPosition(_gridM).Y);
225 203
                             if (imgW < 50)
226 204
                             {
227
-                                imgCanvas.Width = 50;
228
-                                imgX = imgCanvas.Margin.Left;
229
-                                Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
205
+                                _imgCanvas.Width = 50;
206
+                                imgX = _imgCanvas.Margin.Left;
207
+                                Canvas.SetLeft(thu, Canvas.GetLeft(_rectRightDown) - 50);
230 208
                             }
231 209
                             else
232 210
                             {
233
-                                imgCanvas.Width = imgW;
234
-                                imgX = Mouse.GetPosition(GridM).X;
211
+                                _imgCanvas.Width = imgW;
212
+                                imgX = Mouse.GetPosition(_gridM).X;
235 213
                                 Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
236 214
                             }
237 215
                             if (imgH < 50)
238 216
                             {
239
-                                imgCanvas.Height = 50;
240
-                                imgY = imgCanvas.Margin.Top;
241
-                                Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
217
+                                _imgCanvas.Height = 50;
218
+                                imgY = _imgCanvas.Margin.Top;
219
+                                Canvas.SetTop(thu, Canvas.GetTop(_rectRightDown) - 50);
242 220
                             }
243 221
                             else
244 222
                             {
245
-                                imgCanvas.Height = imgH;
246
-                                imgY = Mouse.GetPosition(GridM).Y;
223
+                                _imgCanvas.Height = imgH;
224
+                                imgY = Mouse.GetPosition(_gridM).Y;
247 225
                                 Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
248 226
                             }
249
-                            imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
227
+                            _imgCanvas.Margin = new Thickness(
228
+                                imgX,
229
+                                imgY,
230
+                                0,
231
+                                0
232
+                            );
250 233
 
251 234
                             #endregion 左上
252 235
 
253 236
                             break;
254
-
255 237
                         case "RectRightUp":
256 238
 
257 239
                             #region 右上
258 240
 
259
-                            imgW = Mouse.GetPosition(GridM).X - imgCanvas.Margin.Left;
260
-                            imgH = imgRightDown.Y - (Mouse.GetPosition(GridM).Y);
261
-                            imgX = 0;
262
-                            imgY = 0;
241
+                            imgW = Mouse.GetPosition(_gridM).X - _imgCanvas.Margin.Left;
242
+                            imgH = _imgRightDown.Y - (Mouse.GetPosition(_gridM).Y);
263 243
                             if (imgW < 50)
264 244
                             {
265
-                                imgCanvas.Width = 50;
266
-                                imgX = imgCanvas.Margin.Left;
267
-                                Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
245
+                                _imgCanvas.Width = 50;
246
+                                imgX = _imgCanvas.Margin.Left;
247
+                                Canvas.SetLeft(thu, Canvas.GetLeft(_rectLeftUp) + 50);
268 248
                             }
269 249
                             else
270 250
                             {
271
-                                imgCanvas.Width = imgW;
272
-                                imgX = imgCanvas.Margin.Left;
251
+                                _imgCanvas.Width = imgW;
252
+                                imgX = _imgCanvas.Margin.Left;
273 253
                                 Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
274 254
                             }
275 255
                             if (imgH < 50)
276 256
                             {
277
-                                imgCanvas.Height = 50;
278
-                                imgY = imgCanvas.Margin.Top;
279
-                                Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
257
+                                _imgCanvas.Height = 50;
258
+                                imgY = _imgCanvas.Margin.Top;
259
+                                Canvas.SetTop(thu, Canvas.GetTop(_rectRightDown) - 50);
280 260
                             }
281 261
                             else
282 262
                             {
283
-                                imgCanvas.Height = imgH;
284
-                                imgY = Mouse.GetPosition(GridM).Y;
263
+                                _imgCanvas.Height = imgH;
264
+                                imgY = Mouse.GetPosition(_gridM).Y;
285 265
                                 Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
286 266
                             }
287
-                            imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
267
+                            _imgCanvas.Margin = new Thickness(
268
+                                imgX,
269
+                                imgY,
270
+                                0,
271
+                                0
272
+                            );
288 273
 
289 274
                             #endregion 右上
290 275
 
291 276
                             break;
292
-
293 277
                         case "RectLeftDown":
294 278
 
295 279
                             #region 左下
296 280
 
297
-                            imgW = imgRightDown.X - (Mouse.GetPosition(GridM).X);
298
-                            imgH = Mouse.GetPosition(GridM).Y - imgCanvas.Margin.Top;
299
-                            imgX = 0;
300
-                            imgY = 0;
281
+                            imgW = _imgRightDown.X - (Mouse.GetPosition(_gridM).X);
282
+                            imgH = Mouse.GetPosition(_gridM).Y - _imgCanvas.Margin.Top;
301 283
                             if (imgW < 50)
302 284
                             {
303
-                                imgCanvas.Width = 50;
304
-                                imgX = imgCanvas.Margin.Left;
305
-                                Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
285
+                                _imgCanvas.Width = 50;
286
+                                imgX = _imgCanvas.Margin.Left;
287
+                                Canvas.SetLeft(thu, Canvas.GetLeft(_rectRightDown) - 50);
306 288
                             }
307 289
                             else
308 290
                             {
309
-                                imgCanvas.Width = imgW;
310
-                                imgX = Mouse.GetPosition(GridM).X;
291
+                                _imgCanvas.Width = imgW;
292
+                                imgX = Mouse.GetPosition(_gridM).X;
311 293
                                 Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
312 294
                             }
313 295
                             if (imgH < 50)
314 296
                             {
315
-                                imgCanvas.Height = 50;
316
-                                imgY = imgCanvas.Margin.Top;
317
-                                Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
297
+                                _imgCanvas.Height = 50;
298
+                                imgY = _imgCanvas.Margin.Top;
299
+                                Canvas.SetTop(thu, Canvas.GetTop(_rectLeftUp) + 50);
318 300
                             }
319 301
                             else
320 302
                             {
321
-                                imgCanvas.Height = imgH;
322
-                                imgY = imgCanvas.Margin.Top;
303
+                                _imgCanvas.Height = imgH;
304
+                                imgY = _imgCanvas.Margin.Top;
323 305
                                 Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
324 306
                             }
325
-                            imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
307
+                            _imgCanvas.Margin = new Thickness(
308
+                                imgX,
309
+                                imgY,
310
+                                0,
311
+                                0
312
+                            );
326 313
                             //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(GridM).X);
327 314
                             //imgCanvas.Height = Mouse.GetPosition(GridM).Y - imgCanvas.Margin.Top;
328 315
                             //imgCanvas.Margin = new Thickness(Mouse.GetPosition(GridM).X, imgCanvas.Margin.Top, 0, 0);
@@ -330,31 +317,30 @@ namespace XHWK.WKTool.Utils
330 317
                             #endregion 左下
331 318
 
332 319
                             break;
333
-
334 320
                         case "RectRightDown":
335 321
 
336 322
                             #region 右下
337 323
 
338
-                            imgW = Mouse.GetPosition(GridM).X - imgCanvas.Margin.Left;
339
-                            imgH = Mouse.GetPosition(GridM).Y - imgCanvas.Margin.Top;
324
+                            imgW = Mouse.GetPosition(_gridM).X - _imgCanvas.Margin.Left;
325
+                            imgH = Mouse.GetPosition(_gridM).Y - _imgCanvas.Margin.Top;
340 326
                             if (imgW < 50)
341 327
                             {
342
-                                imgCanvas.Width = 50;
343
-                                Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
328
+                                _imgCanvas.Width = 50;
329
+                                Canvas.SetLeft(thu, Canvas.GetLeft(_rectLeftUp) + 50);
344 330
                             }
345 331
                             else
346 332
                             {
347
-                                imgCanvas.Width = imgW;
333
+                                _imgCanvas.Width = imgW;
348 334
                                 Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
349 335
                             }
350 336
                             if (imgH < 50)
351 337
                             {
352
-                                imgCanvas.Height = 50;
353
-                                Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
338
+                                _imgCanvas.Height = 50;
339
+                                Canvas.SetTop(thu, Canvas.GetTop(_rectLeftUp) + 50);
354 340
                             }
355 341
                             else
356 342
                             {
357
-                                imgCanvas.Height = imgH;
343
+                                _imgCanvas.Height = imgH;
358 344
                                 Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
359 345
                             }
360 346
                             //imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
@@ -364,20 +350,9 @@ namespace XHWK.WKTool.Utils
364 350
                             #endregion 右下
365 351
 
366 352
                             break;
367
-
368
-                        default:
369
-                            break;
370 353
                     }
371
-                    App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
372
-                    {
373
-                        X = imgCanvas.Margin.Left,
374
-                        Y = imgCanvas.Margin.Top
375
-                    };
376
-                    App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
377
-                    {
378
-                        CenterX = imgCanvas.ActualWidth,
379
-                        CenterY = imgCanvas.ActualHeight
380
-                    };
354
+                    App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform { X = _imgCanvas.Margin.Left, Y = _imgCanvas.Margin.Top };
355
+                    App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes = new ScaleTransform { CenterX = _imgCanvas.ActualWidth, CenterY = _imgCanvas.ActualHeight };
381 356
                     App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
382 357
                 }
383 358
             }
@@ -395,10 +370,6 @@ namespace XHWK.WKTool.Utils
395 370
         /// <summary>
396 371
         /// 点击标题栏 隐藏截图的四个点和线
397 372
         /// </summary>
398
-        /// <param name="sender">
399
-        /// </param>
400
-        /// <param name="e">
401
-        /// </param>
402 373
         public void Grid_MouseDown()
403 374
         {
404 375
             HideAngleBorder();
@@ -407,13 +378,9 @@ namespace XHWK.WKTool.Utils
407 378
         /// <summary>
408 379
         /// 鼠标左键点击事件
409 380
         /// </summary>
410
-        /// <param name="sender">
411
-        /// </param>
412
-        /// <param name="e">
413
-        /// </param>
414 381
         public void Window_MouseLeftButtonDown_1()
415 382
         {
416
-            if (RectImgBorder.Visibility != Visibility.Hidden)
383
+            if (_rectImgBorder.Visibility != Visibility.Hidden)
417 384
             {
418 385
                 HideAngleBorder();
419 386
             }
@@ -421,4 +388,4 @@ namespace XHWK.WKTool.Utils
421 388
 
422 389
         #endregion 图片拉伸移动
423 390
     }
424
-}
391
+}

XHWK.WKTool/system/JsonHelper.cs → XHWK.WKTool/Utils/JsonHelper.cs View File

@@ -24,11 +24,11 @@ namespace Common.system
24 24
         /// 类对像转换成json格式
25 25
         /// </summary>
26 26
         /// <param name="t"></param>
27
-        /// <param name="HasNullIgnore">是否忽略NULL值</param>
27
+        /// <param name="hasNullIgnore">是否忽略NULL值</param>
28 28
         /// <returns></returns>
29
-        public static string ToJson(object t, bool HasNullIgnore)
29
+        public static string ToJson(object t, bool hasNullIgnore)
30 30
         {
31
-            if (HasNullIgnore)
31
+            if (hasNullIgnore)
32 32
             {
33 33
                 return JsonConvert.SerializeObject(t, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
34 34
             }

XHWK.WKTool/system/KeyboardHookCommon.cs → XHWK.WKTool/Utils/KeyboardHookCommon.cs View File

@@ -15,10 +15,12 @@ namespace Common.system
15 15
         /// 全局按键按下
16 16
         /// </summary>
17 17
         public event KeyEventHandler KeyDownEvent;
18
+
18 19
         /// <summary>
19 20
         /// 窗口按键按下
20 21
         /// </summary>
21 22
         public event KeyPressEventHandler KeyPressEvent;
23
+
22 24
         /// <summary>
23 25
         /// 全局按键抬起
24 26
         /// </summary>
@@ -26,8 +28,9 @@ namespace Common.system
26 28
 
27 29
         public delegate int HookProc(int nCode, int wParam, IntPtr lParam);
28 30
 
29
-        private static int hKeyboardHook = 0; //声明键盘钩子处理的初始值
30
-                                              //值在Microsoft SDK的Winuser.h里查询
31
+        private static int _hKeyboardHook; //声明键盘钩子处理的初始值
32
+
33
+        //值在Microsoft SDK的Winuser.h里查询
31 34
         /// <summary>
32 35
         /// 线程键盘钩子监听鼠标消息设为2,全局键盘监听鼠标消息设为13
33 36
         /// </summary>
@@ -36,48 +39,62 @@ namespace Common.system
36 39
         /// <summary>
37 40
         /// 声明KeyboardHookProcedure作为HookProc类型
38 41
         /// </summary>
39
-        private HookProc KeyboardHookProcedure;
42
+        private HookProc _keyboardHookProcedure;
40 43
 
41 44
         /// <summary>
42 45
         /// 自己创建窗口按键 
43 46
         /// </summary>
44
-        private const int WM_KEYDOWN = 0x100;//KEYDOWN
47
+        private const int WM_KEYDOWN = 0x100; //KEYDOWN
48
+
45 49
         /// <summary>
46 50
         /// 窗口按键抬起
47 51
         /// </summary>
48
-        private const int WM_KEYUP = 0x101;//KEYUP
52
+        private const int WM_KEYUP = 0x101; //KEYUP
53
+
49 54
         /// <summary>
50 55
         /// 全局系统按键
51 56
         /// </summary>
52
-        private const int WM_SYSKEYDOWN = 0x104;//SYSKEYDOWN
57
+        private const int WM_SYSKEYDOWN = 0x104; //SYSKEYDOWN
58
+
53 59
         /// <summary>
54 60
         /// 全局按键抬起
55 61
         /// </summary>
56
-        private const int WM_SYSKEYUP = 0x105;//SYSKEYUP
62
+        private const int WM_SYSKEYUP = 0x105; //SYSKEYUP
57 63
 
58 64
         //键盘结构
59 65
         [StructLayout(LayoutKind.Sequential)]
60 66
         public class KeyboardHookStruct
61 67
         {
62
-            public int vkCode;  //定一个虚拟键码。该代码必须有一个价值的范围1至254
68
+            public int vkCode; //定一个虚拟键码。该代码必须有一个价值的范围1至254
63 69
             public int scanCode; // 指定的硬件扫描码的关键
64
-            public int flags;  // 键标志
70
+            public int flags; // 键标志
65 71
             public int time; // 指定的时间戳记的这个讯息
66 72
             public int dwExtraInfo; // 指定额外信息相关的信息
67 73
         }
74
+
68 75
         //使用此功能,安装了一个钩子
69 76
         [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
70
-        public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
71
-
77
+        public static extern int SetWindowsHookEx
78
+        (
79
+            int idHook,
80
+            HookProc lpfn,
81
+            IntPtr hInstance,
82
+            int threadId
83
+        );
72 84
 
73 85
         //调用此函数卸载钩子
74 86
         [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
75 87
         public static extern bool UnhookWindowsHookEx(int idHook);
76 88
 
77
-
78 89
         //使用此功能,通过信息钩子继续下一个钩子
79 90
         [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
80
-        public static extern int CallNextHookEx(int idHook, int nCode, int wParam, IntPtr lParam);
91
+        public static extern int CallNextHookEx
92
+        (
93
+            int idHook,
94
+            int nCode,
95
+            int wParam,
96
+            IntPtr lParam
97
+        );
81 98
 
82 99
         // 取得当前线程编号(线程钩子需要用到)
83 100
         [DllImport("kernel32.dll")]
@@ -89,27 +106,34 @@ namespace Common.system
89 106
 
90 107
         //ToAscii职能的转换指定的虚拟键码和键盘状态的相应字符或字符
91 108
         [DllImport("user32")]
92
-        public static extern int ToAscii(int uVirtKey, //[in] 指定虚拟关键代码进行翻译。
93
-                                         int uScanCode, // [in] 指定的硬件扫描码的关键须翻译成英文。高阶位的这个值设定的关键,如果是(不压)
94
-                                         byte[] lpbKeyState, // [in] 指针,以256字节数组,包含当前键盘的状态。每个元素(字节)的数组包含状态的一个关键。如果高阶位的字节是一套,关键是下跌(按下)。在低比特,如果设置表明,关键是对切换。在此功能,只有肘位的CAPS LOCK键是相关的。在切换状态的NUM个锁和滚动锁定键被忽略。
95
-                                         byte[] lpwTransKey, // [out] 指针的缓冲区收到翻译字符或字符。
96
-                                         int fuState); // [in] Specifies whether a menu is active. This parameter must be 1 if a menu is active, or 0 otherwise.
109
+        public static extern int ToAscii
110
+        (
111
+            int uVirtKey, //[in] 指定虚拟关键代码进行翻译。
112
+            int uScanCode, // [in] 指定的硬件扫描码的关键须翻译成英文。高阶位的这个值设定的关键,如果是(不压)
113
+            byte[] lpbKeyState, // [in] 指针,以256字节数组,包含当前键盘的状态。每个元素(字节)的数组包含状态的一个关键。如果高阶位的字节是一套,关键是下跌(按下)。在低比特,如果设置表明,关键是对切换。在此功能,只有肘位的CAPS LOCK键是相关的。在切换状态的NUM个锁和滚动锁定键被忽略。
114
+            byte[] lpwTransKey, // [out] 指针的缓冲区收到翻译字符或字符。
115
+            int fuState
116
+        ); // [in] Specifies whether a menu is active. This parameter must be 1 if a menu is active, or 0 otherwise.
97 117
 
98 118
         //获取按键的状态
99 119
         [DllImport("user32")]
100 120
         public static extern int GetKeyboardState(byte[] pbKeyState);
101 121
 
102
-
103 122
         [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
104 123
         private static extern short GetKeyState(int vKey);
105 124
 
106 125
         public void Start()
107 126
         {
108 127
             // 安装键盘钩子
109
-            if (hKeyboardHook == 0)
128
+            if (_hKeyboardHook == 0)
110 129
             {
111
-                KeyboardHookProcedure = new HookProc(KeyboardHookProc);
112
-                hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, GetModuleHandle(System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName), 0);
130
+                _keyboardHookProcedure = KeyboardHookProc;
131
+                _hKeyboardHook = SetWindowsHookEx(
132
+                    WH_KEYBOARD_LL,
133
+                    _keyboardHookProcedure,
134
+                    GetModuleHandle(System.Diagnostics.Process.GetCurrentProcess().MainModule?.ModuleName),
135
+                    0
136
+                );
113 137
                 //hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
114 138
                 //************************************
115 139
                 //键盘线程钩子
@@ -126,26 +150,24 @@ namespace Common.system
126 150
                 //如果为0,钩子子程与所有的线程关联,即为全局钩子
127 151
                 //************************************
128 152
                 //如果SetWindowsHookEx失败
129
-                if (hKeyboardHook == 0)
153
+                if (_hKeyboardHook == 0)
130 154
                 {
131 155
                     Stop();
132 156
                     throw new Exception("安装键盘钩子失败");
133 157
                 }
134 158
             }
135 159
         }
160
+
136 161
         public void Stop()
137 162
         {
138 163
             bool retKeyboard = true;
139
-
140
-
141
-            if (hKeyboardHook != 0)
164
+            if (_hKeyboardHook != 0)
142 165
             {
143
-                retKeyboard = UnhookWindowsHookEx(hKeyboardHook);
144
-                hKeyboardHook = 0;
166
+                retKeyboard = UnhookWindowsHookEx(_hKeyboardHook);
167
+                _hKeyboardHook = 0;
145 168
             }
146 169
             try
147 170
             {
148
-
149 171
                 if (!(retKeyboard))
150 172
                 {
151 173
                     throw new Exception("卸载钩子失败!");
@@ -153,9 +175,10 @@ namespace Common.system
153 175
             }
154 176
             catch (Exception)
155 177
             {
156
-
178
+                // ignored
157 179
             }
158 180
         }
181
+
159 182
         ////接收SetWindowsHookEx返回值  
160 183
         //private static int _hHookValue = 0;
161 184
         private int KeyboardHookProc(int nCode, int wParam, IntPtr lParam)
@@ -163,11 +186,11 @@ namespace Common.system
163 186
             // 侦听键盘事件
164 187
             if ((nCode >= 0) && (KeyDownEvent != null || KeyUpEvent != null || KeyPressEvent != null))
165 188
             {
166
-                KeyboardHookStruct MyKeyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
189
+                KeyboardHookStruct myKeyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
167 190
                 // raise KeyDown
168 191
                 if (KeyDownEvent != null && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN))
169 192
                 {
170
-                    Keys keyData = (Keys)MyKeyboardHookStruct.vkCode;
193
+                    Keys keyData = (Keys)myKeyboardHookStruct.vkCode;
171 194
                     KeyEventArgs e = new KeyEventArgs(keyData);
172 195
                     KeyDownEvent(this, e);
173 196
                 }
@@ -177,9 +200,15 @@ namespace Common.system
177 200
                 {
178 201
                     byte[] keyState = new byte[256];
179 202
                     GetKeyboardState(keyState);
180
-
181 203
                     byte[] inBuffer = new byte[2];
182
-                    if (ToAscii(MyKeyboardHookStruct.vkCode, MyKeyboardHookStruct.scanCode, keyState, inBuffer, MyKeyboardHookStruct.flags) == 1)
204
+                    if (ToAscii(
205
+                            myKeyboardHookStruct.vkCode,
206
+                            myKeyboardHookStruct.scanCode,
207
+                            keyState,
208
+                            inBuffer,
209
+                            myKeyboardHookStruct.flags
210
+                        ) ==
211
+                        1)
183 212
                     {
184 213
                         KeyPressEventArgs e = new KeyPressEventArgs((char)inBuffer[0]);
185 214
                         KeyPressEvent(this, e);
@@ -189,20 +218,24 @@ namespace Common.system
189 218
                 // 键盘抬起
190 219
                 if (KeyUpEvent != null && (wParam == WM_KEYUP || wParam == WM_SYSKEYUP))
191 220
                 {
192
-                    Keys keyData = (Keys)MyKeyboardHookStruct.vkCode;
221
+                    Keys keyData = (Keys)myKeyboardHookStruct.vkCode;
193 222
                     KeyEventArgs e = new KeyEventArgs(keyData);
194 223
                     KeyUpEvent(this, e);
195 224
                 }
196
-
197 225
             }
198 226
             //如果返回1,则结束消息,这个消息到此为止,不再传递。
199 227
             //如果返回0或调用CallNextHookEx函数则消息出了这个钩子继续往下传递,也就是传给消息真正的接受者
200
-            return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
228
+            return CallNextHookEx(
229
+                _hKeyboardHook,
230
+                nCode,
231
+                wParam,
232
+                lParam
233
+            );
201 234
         }
235
+
202 236
         ~KeyboardHookCommon()
203 237
         {
204 238
             Stop();
205 239
         }
206
-
207 240
     }
208
-}
241
+}

XHWK.WKTool/system/LatticeFileHelper.cs → XHWK.WKTool/Utils/LatticeFileHelper.cs View File

@@ -17,51 +17,62 @@ namespace Common.system
17 17
         /// <summary>
18 18
         /// 打印进程
19 19
         /// </summary>
20
-        public static Process PrintProcess = null;
20
+        public static Process PrintProcess;
21 21
 
22 22
         /// <summary>
23 23
         /// 输出日志文件地址  每个文件2MB左右
24 24
         /// </summary>
25
-        private static string LogPath = "";
25
+        private static string _logPath = "";
26
+
26 27
         /// <summary>
27 28
         /// 运行配置 首次打开必须运行
28 29
         /// </summary>
29 30
         public static void RunPrintConfig()
30 31
         {
31
-            string Path = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintConfig.exe");
32
+            string path = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintConfig.exe");
32 33
             Process myProcess = new Process();
33
-            LogPath = CreateLog();
34
-            myProcess.StartInfo.FileName = Path;   //绝对路径
34
+            _logPath = CreateLog();
35
+            myProcess.StartInfo.FileName = path; //绝对路径
35 36
             //myProcess.StartInfo.Arguments = "";
36
-            myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
37
-            myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
38
-            myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
39
-            myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
37
+            myProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
38
+            myProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
39
+            myProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
40
+            myProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
40 41
             //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
41
-            myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
42
-            myProcess.Start();                 //启动线程
43
-            myProcess.BeginErrorReadLine();    //开始异步读取
44
-            myProcess.WaitForExit();           //阻塞等待进程结束
45
-            myProcess.Close();                 //关闭进程
46
-            myProcess.Dispose();               //释放资源
42
+            myProcess.ErrorDataReceived += Output;
43
+            myProcess.Start(); //启动线程
44
+            myProcess.BeginErrorReadLine(); //开始异步读取
45
+            myProcess.WaitForExit(); //阻塞等待进程结束
46
+            myProcess.Close(); //关闭进程
47
+            myProcess.Dispose(); //释放资源
47 48
         }
48 49
 
49 50
         /// <summary>
50 51
         /// 生成点阵打印文件
51 52
         /// </summary>
52
-        /// <param name="PDFPath">PDF文件位置</param>
53
-        /// <param name="SavePath">保存文件位置 TPF</param>
54
-        /// <param name="PrintResult">输出结果,非0为失败</param>
55
-        /// <param name="StandardError">错误信息</param>
56
-        /// <param name="StandardOutput">输出信息["1536.688.35.70","1536.688.35.71","1536.688.35.72"]</param>
57
-        /// <param name="PointType">0 为方点,1 为圆点 默认方点</param>
58
-        public static void GeneratingPDF(string PDFPath, string SavePath, out int PrintResult, out string StandardError, out string StandardOutput, int PointType = 0)
53
+        /// <param name="pdfPath">PDF文件位置</param>
54
+        /// <param name="savePath">保存文件位置 TPF</param>
55
+        /// <param name="printResult">输出结果,非0为失败</param>
56
+        /// <param name="standardError">错误信息</param>
57
+        /// <param name="standardOutput">输出信息["1536.688.35.70","1536.688.35.71","1536.688.35.72"]</param>
58
+        /// <param name="pointType">0 为方点,1 为圆点 默认方点</param>
59
+        public static void GeneratingPdf
60
+        (
61
+            string pdfPath,
62
+            string savePath,
63
+            out int printResult,
64
+            out string standardError,
65
+            out string standardOutput,
66
+            int pointType = 0
67
+        )
59 68
         {
60 69
             //XML点阵文件位置
61
-            string XmlFile = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/print_license.xml");
62
-            string ContentParameter = null;
63
-            ContentParameter = "-sMode=Generate \"-sPDF=" + PDFPath + "\" \"-sLIC=" + XmlFile + "\" \"-oTPF=" + SavePath + "\" \"-dType=" + PointType + "\" ";//[-dType=0] [-dPrint=0] [-pStart=0]
70
+            string xmlFile = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/print_license.xml");
71
+            string contentParameter;
72
+            contentParameter = "-sMode=Generate \"-sPDF=" + pdfPath + "\" \"-sLIC=" + xmlFile + "\" \"-oTPF=" + savePath + "\" \"-dType=" + pointType + "\" "; //[-dType=0] [-dPrint=0] [-pStart=0]
73
+
64 74
             #region 制作点阵文件参数说明
75
+
65 76
             //-sMode = Generate - sPDF = d:\l\e.pdf - sLIC = d:\l\a.xml - oPDF = d:\l\11210.pdf"
66 77
             //当 - sMode = Generate,参数如下:
67 78
             //PrintTool.exe - sMode = Generate - sPDF = -sLIC = < -oPDF =| -oTPF=> [dType=] [-dPrint] [-pStart =]
@@ -72,96 +83,111 @@ namespace Common.system
72 83
             //- dType 0 为方点,1 为圆点;可选参数,默认 0。详细参数区别,参见 3.1 点阵形状
73 84
             //- dPrint 0 为激光打印机,1 为印刷机;可选参数,默认 0。详细参数区别,参见 3.2 点阵 PDF 适用打印场景
74 85
             //- pStart 整数,选择从哪页点阵资源开始制作点阵文件, 即起始点阵资源页序号;可选参数,默认0。关于 - pStart 的功能说明,参见 1.3.1.高级设置
86
+
75 87
             #endregion
88
+
76 89
             while (PrintProcess != null)
77 90
             {
78 91
                 Thread.Sleep(100);
79 92
             }
80
-            Process[] KillProcessArray = Process.GetProcessesByName("PrintTool");
81
-            foreach (Process KillProcess in KillProcessArray)
93
+            Process[] killProcessArray = Process.GetProcessesByName("PrintTool");
94
+            foreach (Process killProcess in killProcessArray)
82 95
             {
83
-                KillProcess.Kill();
96
+                killProcess.Kill();
84 97
             }
85 98
             PrintProcess = new Process();
86
-            LogPath = CreateLog();
87
-            PrintProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintTool.exe");   //绝对路径
88
-            PrintProcess.StartInfo.Arguments = ContentParameter;
89
-            PrintProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
90
-            PrintProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
99
+            _logPath = CreateLog();
100
+            PrintProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintTool.exe"); //绝对路径
101
+            PrintProcess.StartInfo.Arguments = contentParameter;
102
+            PrintProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
103
+            PrintProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
91 104
             PrintProcess.StartInfo.RedirectStandardOutput = true;
92
-            PrintProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
93
-            PrintProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
105
+            PrintProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
106
+            PrintProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
94 107
             //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
95
-            PrintProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
96
-            PrintProcess.Start();                 //启动线程
97
-            PrintProcess.WaitForExit();           //阻塞等待进程结束
98
-            StandardError = PrintProcess.StandardError.ReadToEnd();
99
-            StandardOutput = PrintProcess.StandardOutput.ReadToEnd();
108
+            PrintProcess.ErrorDataReceived += Output;
109
+            PrintProcess.Start(); //启动线程
110
+            PrintProcess.WaitForExit(); //阻塞等待进程结束
111
+            standardError = PrintProcess.StandardError.ReadToEnd();
112
+            standardOutput = PrintProcess.StandardOutput.ReadToEnd();
100 113
             //PrintProcess.BeginErrorReadLine();    //开始异步读取
101
-            Output("【制作点阵文件】错误:" + StandardError);
102
-            Output("【制作点阵文件】返回信息:" + StandardOutput);
103
-            PrintResult = PrintProcess.ExitCode;     //打印结果 非0则为打印失败
104
-            Output("【制作点阵文件】" + ContentParameter);//记录打印日志
105
-            PrintProcess.Close();                 //关闭进程
106
-            PrintProcess.Dispose();               //释放资源
114
+            Output("【制作点阵文件】错误:" + standardError);
115
+            Output("【制作点阵文件】返回信息:" + standardOutput);
116
+            printResult = PrintProcess.ExitCode; //打印结果 非0则为打印失败
117
+            Output("【制作点阵文件】" + contentParameter); //记录打印日志
118
+            PrintProcess.Close(); //关闭进程
119
+            PrintProcess.Dispose(); //释放资源
120
+
107 121
             #region 进程是否已经释放
108
-            bool IsRunning = true;
109
-            while (IsRunning)
122
+
123
+            bool isRunning = true;
124
+            while (isRunning)
110 125
             {
111
-                IsRunning = false;
112
-                Process[] ProcessArray = Process.GetProcessesByName("PrintTool");
113
-                foreach (Process KillProcess in ProcessArray)
126
+                isRunning = false;
127
+                Process[] processArray = Process.GetProcessesByName("PrintTool");
128
+                if (processArray.Length > 0)
114 129
                 {
115
-                    IsRunning = true;
130
+                    isRunning = true;
116 131
                     Thread.Sleep(100);
117 132
                 }
118 133
             }
134
+
119 135
             #endregion
136
+
120 137
             PrintProcess = null;
121 138
         }
122 139
 
123 140
         /// <summary>
124 141
         /// 获取打印机列表
125 142
         /// </summary>
126
-        /// <param name="DefaultPrinter">默认打印机</param>
143
+        /// <param name="defaultPrinter">默认打印机</param>
127 144
         /// <returns>打印机列表</returns>
128
-        public static List<string> GetPrinterList(out string DefaultPrinter)
145
+        public static List<string> GetPrinterList(out string defaultPrinter)
129 146
         {
130
-            List<string> PrintersList = new List<string>();
131
-            DefaultPrinter = null;
147
+            List<string> printersList = new List<string>();
148
+            defaultPrinter = null;
132 149
             try
133 150
             {
134 151
                 PrintDocument print = new PrintDocument();
135
-                DefaultPrinter = print.PrinterSettings.PrinterName;//默认打印机名
136
-                foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称
152
+                defaultPrinter = print.PrinterSettings.PrinterName; //默认打印机名
153
+                foreach (string sPrint in PrinterSettings.InstalledPrinters) //获取所有打印机名称
137 154
                 {
138
-                    PrintersList.Add(sPrint);
155
+                    printersList.Add(sPrint);
139 156
                 }
140 157
             }
141 158
             catch (Exception)
142 159
             {
143
-
160
+                // ignored
144 161
             }
145
-            return PrintersList;
162
+            return printersList;
146 163
         }
147 164
 
148 165
         /// <summary>
149 166
         /// 打印TPF点阵文件
150 167
         /// </summary>
151
-        /// <param name="TPFPath">TPF路径</param>
152
-        /// <param name="PrinterNum">打印份数</param>
153
-        /// <param name="PrinterName">打印机名称</param>
154
-        /// <param name="PrintResult">输出结果,非0为失败</param>
155
-        /// <param name="StandardError">错误信息</param>
156
-        /// <param name="StandardOutput">输出信息</param>
157
-        public static void PrinterTPFFile(string TPFPath, int PrinterNum, string PrinterName, out int PrintResult, out string StandardError, out string StandardOutput)
168
+        /// <param name="tpfPath">TPF路径</param>
169
+        /// <param name="printerNum">打印份数</param>
170
+        /// <param name="printerName">打印机名称</param>
171
+        /// <param name="printResult">输出结果,非0为失败</param>
172
+        /// <param name="standardError">错误信息</param>
173
+        /// <param name="standardOutput">输出信息</param>
174
+        public static void PrinterTpfFile
175
+        (
176
+            string tpfPath,
177
+            int printerNum,
178
+            string printerName,
179
+            out int printResult,
180
+            out string standardError,
181
+            out string standardOutput
182
+        )
158 183
         {
159
-            TPFPath = TPFPath.Replace("/", "\\");
184
+            tpfPath = tpfPath.Replace("/", "\\");
160 185
             //XML点阵文件位置
161 186
             //string XmlFile = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/print_license.xml");
162
-            string ContentParameter = null;
163
-            ContentParameter = " -sMode=Print \"-sTPF=" + TPFPath + "\" \"-sPrinter=" + PrinterName + "\" \"-dCopy=" + PrinterNum + "\"";//\"-dPaperSize=9\"
187
+            string contentParameter = " -sMode=Print \"-sTPF=" + tpfPath + "\" \"-sPrinter=" + printerName + "\" \"-dCopy=" + printerNum + "\""; //\"-dPaperSize=9\"
188
+
164 189
             #region 打印参数说明
190
+
165 191
             //-sMode = Print,参数如下:
166 192
             //PrintTool.exe - sMode = Print - sTPF = [-dCopy =][-dPaperSize =] - sPrinter =
167 193
             //-sTPF 需要打印的 TPF 文件路径
@@ -171,51 +197,57 @@ namespace Common.system
171 197
             //- sPrinter 打印机名称
172 198
             // 打印完成后,如果打印成功,PrintTool.exe 退出值为 0。
173 199
             //如果打印失败,程序退出值为非 0。
200
+
174 201
             #endregion
202
+
175 203
             while (PrintProcess != null)
176 204
             {
177 205
                 Thread.Sleep(100);
178 206
             }
179
-            Process[] KillProcessArray = Process.GetProcessesByName("PrintTool");
180
-            foreach (Process KillProcess in KillProcessArray)
207
+            Process[] killProcessArray = Process.GetProcessesByName("PrintTool");
208
+            foreach (Process killProcess in killProcessArray)
181 209
             {
182
-                KillProcess.Kill();
210
+                killProcess.Kill();
183 211
             }
184 212
             PrintProcess = new Process();
185
-            LogPath = CreateLog();
186
-            PrintProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintTool.exe").Replace("/", "\\"); ;   //绝对路径
187
-            PrintProcess.StartInfo.Arguments = ContentParameter;
188
-            PrintProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
189
-            PrintProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
213
+            _logPath = CreateLog();
214
+            PrintProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintTool.exe").Replace("/", "\\");
215
+            PrintProcess.StartInfo.Arguments = contentParameter;
216
+            PrintProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
217
+            PrintProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
190 218
             PrintProcess.StartInfo.RedirectStandardOutput = true;
191
-            PrintProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
192
-            PrintProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
219
+            PrintProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
220
+            PrintProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
193 221
             //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
194
-            PrintProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
195
-            PrintProcess.Start();                 //启动线程
222
+            PrintProcess.ErrorDataReceived += Output;
223
+            PrintProcess.Start(); //启动线程
196 224
             //PrintProcess.BeginErrorReadLine();    //开始异步读取
197
-            PrintProcess.WaitForExit();           //阻塞等待进程结束
198
-            StandardError = PrintProcess.StandardError.ReadToEnd();
199
-            StandardOutput = PrintProcess.StandardOutput.ReadToEnd();
200
-            Output("【制作点阵文件】错误:" + StandardError);
201
-            Output("【制作点阵文件】返回信息:" + StandardOutput);
202
-            PrintResult = PrintProcess.ExitCode;     //打印结果 非0则为打印失败
203
-            Output("【打印TPF文件】" + ContentParameter);//记录打印日志
204
-            PrintProcess.Close();                 //关闭进程
205
-            PrintProcess.Dispose();               //释放资源
225
+            PrintProcess.WaitForExit(); //阻塞等待进程结束
226
+            standardError = PrintProcess.StandardError.ReadToEnd();
227
+            standardOutput = PrintProcess.StandardOutput.ReadToEnd();
228
+            Output("【制作点阵文件】错误:" + standardError);
229
+            Output("【制作点阵文件】返回信息:" + standardOutput);
230
+            printResult = PrintProcess.ExitCode; //打印结果 非0则为打印失败
231
+            Output("【打印TPF文件】" + contentParameter); //记录打印日志
232
+            PrintProcess.Close(); //关闭进程
233
+            PrintProcess.Dispose(); //释放资源
234
+
206 235
             #region 进程是否已经释放
207
-            bool IsRunning = true;
208
-            while (IsRunning)
236
+
237
+            bool isRunning = true;
238
+            while (isRunning)
209 239
             {
210
-                IsRunning = false;
211
-                Process[] ProcessArray = Process.GetProcessesByName("PrintTool");
212
-                foreach (Process KillProcess in ProcessArray)
240
+                isRunning = false;
241
+                Process[] processArray = Process.GetProcessesByName("PrintTool");
242
+                if (processArray.Length > 0)
213 243
                 {
214
-                    IsRunning = true;
244
+                    isRunning = true;
215 245
                     Thread.Sleep(100);
216 246
                 }
217 247
             }
248
+
218 249
             #endregion
250
+
219 251
             PrintProcess = null;
220 252
         }
221 253
 
@@ -225,52 +257,52 @@ namespace Common.system
225 257
         /// <returns></returns>
226 258
         private static string CreateLog()
227 259
         {
228
-            string LogFileName = DateTime.Now.ToString("yyyyMMdd");
229
-            string LogFilePath = FileToolsCommon.GetFileAbsolutePath("/Log/PrintLog/");
230
-            FileToolsCommon.CreateDirectory(LogFilePath);
231
-            string LogName = LogFilePath + LogFileName + ".log";
260
+            string logFileName = DateTime.Now.ToString("yyyyMMdd");
261
+            string logFilePath = FileToolsCommon.GetFileAbsolutePath("/Log/PrintLog/");
262
+            FileToolsCommon.CreateDirectory(logFilePath);
263
+            string logName = logFilePath + logFileName + ".log";
232 264
             try
233 265
             {
234
-                if (!FileToolsCommon.IsExistFile(LogName))
266
+                if (!FileToolsCommon.IsExistFile(logName))
235 267
                 {
236
-                    FileToolsCommon.CreateFile(LogName);
268
+                    FileToolsCommon.CreateFile(logName);
237 269
                     //FileToolsCommon.AppendText(LogName, "\r\n****************************************************************************************************" +
238 270
                     //    "****************************************************************************************************\r\n");
239
-                    return LogName;
271
+                    return logName;
240 272
                 }
241 273
                 else
242 274
                 {
243 275
                     int num = 0;
244
-                    while (FileToolsCommon.GetFileSizeByMb(LogName) > 2)
276
+                    while (FileToolsCommon.GetFileSizeByMb(logName) > 2)
245 277
                     {
246 278
                         num++;
247
-                        LogName = LogFilePath + LogFileName + "_" + num + ".log";
248
-                        FileToolsCommon.CreateFile(LogName);
279
+                        logName = logFilePath + logFileName + "_" + num + ".log";
280
+                        FileToolsCommon.CreateFile(logName);
249 281
                     }
250 282
                     //FileToolsCommon.AppendText(LogName, "\r\n****************************************************************************************************" +
251 283
                     //    "****************************************************************************************************\r\n");
252
-                    return LogName;
284
+                    return logName;
253 285
                 }
254 286
             }
255 287
             catch (Exception)
256 288
             {
257
-                return LogName;
289
+                return logName;
258 290
             }
259 291
         }
260 292
 
261 293
         /// <summary>
262 294
         /// 输出日志
263 295
         /// </summary>
264
-        /// <param name="Message"></param>
265
-        private static void Output(string Message)
296
+        /// <param name="message"></param>
297
+        private static void Output(string message)
266 298
         {
267
-            if (!string.IsNullOrEmpty(Message))
299
+            if (!string.IsNullOrEmpty(message))
268 300
             {
269
-                FileToolsCommon.AppendText(LogPath, Message + "\r\n");
270
-                FileToolsCommon.AppendText(LogPath, "\r\n****************************************************************************************************" +
271
-                         "****************************************************************************************************\r\n");
301
+                FileToolsCommon.AppendText(_logPath, message + "\r\n");
302
+                FileToolsCommon.AppendText(_logPath, "\r\n****************************************************************************************************" + "****************************************************************************************************\r\n");
272 303
             }
273 304
         }
305
+
274 306
         /// <summary>
275 307
         /// 输出结果
276 308
         /// </summary>
@@ -281,4 +313,4 @@ namespace Common.system
281 313
             Output(output.Data);
282 314
         }
283 315
     }
284
-}
316
+}

XHWK.WKTool/system/LogHelper.cs → XHWK.WKTool/Utils/LogHelper.cs View File

@@ -5,8 +5,6 @@ using System.IO;
5 5
 
6 6
 namespace Common.system
7 7
 {
8
-    using XHWK.WKTool.system;
9
-
10 8
     public class LogHelper
11 9
     {
12 10
         public static readonly log4net.ILog Loginfo = log4net.LogManager.GetLogger("loginfo");

XHWK.WKTool/system/MouseEventCommon.cs → XHWK.WKTool/Utils/MouseEventCommon.cs View File

@@ -20,11 +20,8 @@ namespace Common.system
20 20
 
21 21
         /// <summary>   
22 22
         /// 获取鼠标的坐标   
23
-        /// </summary>   
24
-        /// <param name="lpPoint">传址参数,坐标point类型</param>   
23
+        /// </summary>
25 24
         /// <returns>获取成功返回真</returns>   
26
-
27
-
28 25
         [DllImport("user32.dll", CharSet = CharSet.Auto)]
29 26
         public static extern bool GetCursorPos(out POINT pt);
30 27
 

XHWK.WKTool/system/PdfTrunImage.cs → XHWK.WKTool/Utils/PdfTrunImage.cs View File

@@ -32,8 +32,16 @@ namespace Common.system
32 32
         /// <param name="endPageNum">从PDF文档的第几页开始停止转换</param>
33 33
         /// <param name="imageFormat">设置所需图片格式</param>
34 34
         /// <param name="definition">设置图片的清晰度,数字越大越清晰</param>
35
-        public static List<string> ConvertPDF2Image(string pdfInputPath, string imageOutputPath,
36
-            string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, Definition definition)
35
+        public static List<string> ConvertPdf2Image
36
+        (
37
+            string pdfInputPath,
38
+            string imageOutputPath,
39
+            string imageName,
40
+            int startPageNum,
41
+            int endPageNum,
42
+            ImageFormat imageFormat,
43
+            Definition definition
44
+        )
37 45
         {
38 46
             List<string> images = new List<string>();
39 47
             try
@@ -57,7 +65,6 @@ namespace Common.system
57 65
                 }
58 66
                 if (startPageNum > endPageNum)
59 67
                 {
60
-                    int tempPageNum = startPageNum;
61 68
                     startPageNum = endPageNum;
62 69
                     endPageNum = startPageNum;
63 70
                 }
@@ -66,7 +73,7 @@ namespace Common.system
66 73
                 for (int i = startPageNum; i <= endPageNum; i++)
67 74
                 {
68 75
                     Bitmap pageImage = pdfFile.GetPageImage(i - 1, 56 * (int)definition);
69
-                    string imgPath = imageOutputPath + imageName + i.ToString() + "." + imageFormat.ToString();
76
+                    string imgPath = imageOutputPath + imageName + i.ToString() + "." + imageFormat;
70 77
                     pageImage.Save(imgPath, imageFormat);
71 78
                     images.Add(imgPath);
72 79
                     // 返回的图片绝对路径集合
@@ -78,8 +85,7 @@ namespace Common.system
78 85
             }
79 86
             catch (System.Exception ex)
80 87
             {
81
-                LogHelper.Logerror.Error("PDF转图片" +
82
-                    "【PdfTrunImage】" + ex.Message, ex);
88
+                LogHelper.Logerror.Error("PDF转图片" + "【PdfTrunImage】" + ex.Message, ex);
83 89
                 images = new List<string>();
84 90
                 return images;
85 91
             }

XHWK.WKTool/system/PrimaryScreen.cs → XHWK.WKTool/Utils/PrimaryScreen.cs View File

@@ -78,9 +78,9 @@ namespace Common.system
78 78
             get
79 79
             {
80 80
                 IntPtr hdc = GetDC(IntPtr.Zero);
81
-                int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);
81
+                int dpiX = GetDeviceCaps(hdc, LOGPIXELSX);
82 82
                 ReleaseDC(IntPtr.Zero, hdc);
83
-                return DpiX;
83
+                return dpiX;
84 84
             }
85 85
         }
86 86
         /// <summary>
@@ -91,9 +91,9 @@ namespace Common.system
91 91
             get
92 92
             {
93 93
                 IntPtr hdc = GetDC(IntPtr.Zero);
94
-                int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);
94
+                int dpiX = GetDeviceCaps(hdc, LOGPIXELSY);
95 95
                 ReleaseDC(IntPtr.Zero, hdc);
96
-                return DpiX;
96
+                return dpiX;
97 97
             }
98 98
         }
99 99
         /// <summary>
@@ -126,9 +126,9 @@ namespace Common.system
126 126
                 GetDeviceCaps(hdc, DESKTOPHORZRES);
127 127
                 /* int d = */
128 128
                 GetDeviceCaps(hdc, HORZRES);
129
-                float ScaleX = GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
129
+                float mScaleX = GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
130 130
                 ReleaseDC(IntPtr.Zero, hdc);
131
-                return ScaleX;
131
+                return mScaleX;
132 132
             }
133 133
         }
134 134
         /// <summary>
@@ -139,9 +139,9 @@ namespace Common.system
139 139
             get
140 140
             {
141 141
                 IntPtr hdc = GetDC(IntPtr.Zero);
142
-                float ScaleY = (float)GetDeviceCaps(hdc, DESKTOPVERTRES) / GetDeviceCaps(hdc, VERTRES);
142
+                float scaleY = (float)GetDeviceCaps(hdc, DESKTOPVERTRES) / GetDeviceCaps(hdc, VERTRES);
143 143
                 ReleaseDC(IntPtr.Zero, hdc);
144
-                return ScaleY;
144
+                return scaleY;
145 145
             }
146 146
         }
147 147
 
@@ -158,7 +158,12 @@ namespace Common.system
158 158
             get
159 159
             {
160 160
                 RectangleF rect = System.Windows.Forms.Screen.GetWorkingArea(new System.Drawing.Point((int)ScaleScreenSize.Width, (int)ScaleScreenSize.Height));
161
-                return new RectangleF(((float)rect.X) / (DpiX / 96f), ((float)rect.Y) / (DpiX / 96f), ((float)rect.Width) / (DpiX / 96f), ((float)rect.Height) / (DpiY / 96f));
161
+                return new RectangleF(
162
+                    rect.X / (DpiX / 96f),
163
+                    rect.Y / (DpiX / 96f),
164
+                    rect.Width / (DpiX / 96f),
165
+                    rect.Height / (DpiY / 96f)
166
+                );
162 167
             }
163 168
         }
164 169
         #endregion

XHWK.WKTool/system/QueueSync.cs → XHWK.WKTool/Utils/QueueSync.cs View File

@@ -1,8 +1,4 @@
1
-using System;
2
-using System.Collections.Generic;
3
-using System.Linq;
4
-using System.Text;
5
-using System.Threading.Tasks;
1
+using System.Collections.Generic;
6 2
 
7 3
 namespace Common.system
8 4
 {
@@ -14,25 +10,8 @@ namespace Common.system
14 10
     /// <typeparam name="T"></typeparam>
15 11
     public class QueueSync<T>
16 12
     {
17
-        int _maxcount = 10000;
18
-        Queue<T> _queue = new Queue<T>();
19
-        /// <summary>
20
-        /// 获取该队列包含的元素数
21
-        /// </summary>
22
-        public int Count
23
-        {
24
-            get
25
-            {
26
-                if (_queue == null)
27
-                {
28
-                    return 0;
29
-                }
30
-                else
31
-                {
32
-                    return _queue.Count;
33
-                }
34
-            }
35
-        }
13
+        int _maxcount;
14
+        private Queue<T> _queue = new Queue<T>();
36 15
 
37 16
         /// <summary>
38 17
         /// 默认1000
@@ -45,7 +24,6 @@ namespace Common.system
45 24
         /// <param name="maxcount"></param>
46 25
         public QueueSync(int maxcount)
47 26
         {
48
-            //_maxcount = Math.Max(maxcount, _maxcount);
49 27
             _maxcount = maxcount;
50 28
         }
51 29
 
@@ -56,7 +34,6 @@ namespace Common.system
56 34
         /// <returns></returns>
57 35
         public bool Enqueue(T obj)
58 36
         {
59
-            bool result = false;
60 37
             lock (this)
61 38
             {
62 39
                 if (_queue.Count > _maxcount)
@@ -64,9 +41,8 @@ namespace Common.system
64 41
                     _queue.Dequeue();
65 42
                 }
66 43
                 _queue.Enqueue(obj);
67
-                result = true;
68 44
             }
69
-            return result;
45
+            return true;
70 46
         }
71 47
         /// <summary>
72 48
         /// 出队列
@@ -83,7 +59,7 @@ namespace Common.system
83 59
                 }
84 60
                 catch
85 61
                 {
86
-
62
+                    // ignored
87 63
                 }
88 64
             }
89 65
             return obj;

+ 102
- 0
XHWK.WKTool/Utils/SplashScreen.cs View File

@@ -0,0 +1,102 @@
1
+using System;
2
+using System.Reflection;
3
+using System.Threading;
4
+using System.Windows.Forms;
5
+
6
+namespace Common.system
7
+{
8
+    /// <summary>
9
+    /// 解决闪屏  加载等待 
10
+    /// 创建人:赵耀
11
+    /// 创建时间:2018年11月27日
12
+    /// </summary>
13
+    public class SplashScreen
14
+    {
15
+        private static object _obj = new object();
16
+
17
+        private static Form _splashForm;
18
+
19
+        private static Thread _splashThread;
20
+
21
+        private delegate void ChangeFormTextdelegate(string s);
22
+
23
+        public static void Show(Type splashFormType)
24
+        {
25
+            if (_splashThread != null)
26
+            {
27
+                return;
28
+            }
29
+
30
+            if (splashFormType == null)
31
+            {
32
+                throw (new Exception());
33
+            }
34
+            _splashThread = new Thread(
35
+                delegate()
36
+                {
37
+                    CreateInstance(splashFormType);
38
+                    Application.Run(_splashForm);
39
+                }
40
+            ) { IsBackground = true };
41
+            _splashThread.SetApartmentState(ApartmentState.STA);
42
+            _splashThread.Start();
43
+        }
44
+
45
+        public static void ChangeTitle(string status)
46
+        {
47
+            ChangeFormTextdelegate de = ChangeText;
48
+            _splashForm.Invoke(de, status);
49
+        }
50
+
51
+
52
+
53
+        public static void Close()
54
+        {
55
+            if (_splashThread == null || _splashForm == null)
56
+            {
57
+                return;
58
+            }
59
+            try
60
+            {
61
+                _splashForm.Invoke(new MethodInvoker(_splashForm.Close));
62
+            }
63
+            catch (Exception)
64
+            {
65
+                // ignored
66
+            }
67
+            _splashThread = null;
68
+            _splashForm = null;
69
+        }
70
+
71
+        private static void ChangeText(string title)
72
+        {
73
+            _splashForm.Text = title;
74
+        }
75
+
76
+        private static void CreateInstance(Type formType)
77
+        {
78
+            if (_splashForm == null)
79
+            {
80
+                lock (_obj)
81
+                {
82
+                    object obj = formType.InvokeMember(
83
+                        null,
84
+                        BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance,
85
+                        null,
86
+                        null,
87
+                        null
88
+                    );
89
+                    _splashForm = obj as Form;
90
+                    if (_splashForm != null)
91
+                    {
92
+                        _splashForm.TopMost = true;
93
+                        _splashForm.ShowInTaskbar = false;
94
+                        _splashForm.BringToFront();
95
+                        _splashForm.StartPosition = FormStartPosition.CenterScreen;
96
+                    }
97
+                }
98
+            }
99
+        }
100
+
101
+    }
102
+}

XHWK.WKTool/system/XmlUtilHelper.cs → XHWK.WKTool/Utils/XmlUtilHelper.cs View File

@@ -36,11 +36,12 @@ namespace Common.system
36 36
                 return null;
37 37
             }
38 38
         }
39
+
39 40
         /// <summary>
40 41
         /// 反序列化
41 42
         /// </summary>
42 43
         /// <param name="type"></param>
43
-        /// <param name="xml"></param>
44
+        /// <param name="stream"></param>
44 45
         /// <returns></returns>
45 46
         public static object Deserialize(Type type, Stream stream)
46 47
         {
@@ -48,17 +49,18 @@ namespace Common.system
48 49
 
49 50
             return xmldes.Deserialize(stream);
50 51
         }
52
+
51 53
         /// <summary>
52 54
         /// 反序列化实体
53 55
         /// </summary>
54 56
         /// <typeparam name="T"></typeparam>
55
-        /// <param name="strXML"></param>
57
+        /// <param name="strXml"></param>
56 58
         /// <returns></returns>
57
-        public static T DESerializer<T>(string strXML) where T : class
59
+        public static T DeSerializer<T>(string strXml) where T : class
58 60
         {
59 61
             try
60 62
             {
61
-                using (StringReader sr = new StringReader(strXML))
63
+                using (StringReader sr = new StringReader(strXml))
62 64
                 {
63 65
                     XmlSerializer serializer = new XmlSerializer(typeof(T));
64 66
                     return serializer.Deserialize(sr) as T;
@@ -72,8 +74,7 @@ namespace Common.system
72 74
 
73 75
         /// <summary>  
74 76
         /// 从xml序列中反序列化  
75
-        /// </summary>  
76
-        /// <param name="objname"></param>  
77
+        /// </summary>
77 78
         /// <returns></returns>  
78 79
         public static object Deserailize(Type type, string filename)
79 80
         {
@@ -107,17 +108,17 @@ namespace Common.system
107 108
         {
108 109
             if (!string.IsNullOrEmpty(xmlStr))
109 110
             {
110
-                StringReader StrStream = null;
111
-                XmlTextReader Xmlrdr = null;
111
+                StringReader strStream = null;
112
+                XmlTextReader xmlrdr = null;
112 113
                 try
113 114
                 {
114 115
                     DataSet ds = new DataSet();
115 116
                     //读取字符串中的信息  
116
-                    StrStream = new StringReader(xmlStr);
117
+                    strStream = new StringReader(xmlStr);
117 118
                     //获取StrStream中的数据  
118
-                    Xmlrdr = new XmlTextReader(StrStream);
119
+                    xmlrdr = new XmlTextReader(strStream);
119 120
                     //ds获取Xmlrdr中的数据                 
120
-                    ds.ReadXml(Xmlrdr);
121
+                    ds.ReadXml(xmlrdr);
121 122
                     return ds.Tables[0];
122 123
                 }
123 124
                 catch (Exception)
@@ -127,11 +128,11 @@ namespace Common.system
127 128
                 finally
128 129
                 {
129 130
                     //释放资源  
130
-                    if (Xmlrdr != null)
131
+                    if (xmlrdr != null)
131 132
                     {
132
-                        Xmlrdr.Close();
133
-                        StrStream.Close();
134
-                        StrStream.Dispose();
133
+                        xmlrdr.Close();
134
+                        strStream.Close();
135
+                        strStream.Dispose();
135 136
                     }
136 137
                 }
137 138
             }
@@ -151,7 +152,6 @@ namespace Common.system
151 152
         {
152 153
             using (StringWriter sw = new StringWriter())
153 154
             {
154
-                Type t = obj.GetType();
155 155
                 XmlSerializer serializer = new XmlSerializer(obj.GetType());
156 156
                 serializer.Serialize(sw, obj);
157 157
                 sw.Close();
@@ -166,24 +166,23 @@ namespace Common.system
166 166
         /// <returns></returns>
167 167
         public static string Serializer(Type type, object obj)
168 168
         {
169
-            MemoryStream Stream = new MemoryStream();
169
+            MemoryStream stream = new MemoryStream();
170 170
             XmlSerializer xml = new XmlSerializer(type);
171 171
             try
172 172
             {
173 173
                 //序列化对象
174
-                xml.Serialize(Stream, obj);
174
+                xml.Serialize(stream, obj);
175 175
             }
176 176
             catch (InvalidOperationException)
177 177
             {
178 178
                 //Logger.Log4NetHelp.Error("序列化失败:", ex);
179 179
             }
180
-            Stream.Position = 0;
181
-            StreamReader sr = new StreamReader(Stream);
180
+            stream.Position = 0;
181
+            StreamReader sr = new StreamReader(stream);
182 182
             string str = sr.ReadToEnd();
183 183
 
184 184
             sr.Dispose();
185
-            Stream.Dispose();
186
-
185
+            stream.Dispose();
187 186
             return str;
188 187
         }
189 188
 

+ 22
- 10
XHWK.WKTool/Utils/ZAsposeUtil.cs View File

@@ -14,14 +14,15 @@ namespace XHWK.WKTool.Utils
14 14
         /// 将Word文档转换为图片的方法(该方法基于第三方DLL),
15 15
         /// 你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\","ImageFile", 1, 20);
16 16
         /// </summary>
17
-        /// <param name="pdfInputPath">Word文件路径</param>
17
+        /// <param name="wordInputPath"></param>
18 18
         /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
19 19
         /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
20 20
         /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
21 21
         /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
22 22
         /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
23 23
         /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
24
-        public static List<string> ConvertWordToImage(
24
+        public static List<string> ConvertWordToImage
25
+        (
25 26
             string wordInputPath,
26 27
             string imageOutputPath,
27 28
             string imageName,
@@ -29,7 +30,7 @@ namespace XHWK.WKTool.Utils
29 30
             int endPageNum = 0,
30 31
             Aspose.Words.SaveFormat imageFormat = Aspose.Words.SaveFormat.Png,
31 32
             float resolution = 128
32
-            )
33
+        )
33 34
         {
34 35
             // 返回的图片绝对路径集合
35 36
             List<string> images = new List<string>();
@@ -41,11 +42,21 @@ namespace XHWK.WKTool.Utils
41 42
                 // validate parameter
42 43
                 if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
43 44
                 if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
44
-                if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
45
+                if (!Directory.Exists(imageOutputPath))
46
+                {
47
+                    if (imageOutputPath != null)
48
+                    {
49
+                        Directory.CreateDirectory(imageOutputPath);
50
+                    }
51
+                }
45 52
                 if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
46 53
                 if (startPageNum <= 0) { startPageNum = 1; }
47 54
                 if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
48
-                if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
55
+                if (startPageNum > endPageNum)
56
+                {
57
+                    startPageNum = endPageNum;
58
+                    endPageNum = startPageNum;
59
+                }
49 60
                 if (resolution <= 0) { resolution = 128; }
50 61
 
51 62
                 ImageSaveOptions imageSaveOptions = new ImageSaveOptions(imageFormat)
@@ -57,12 +68,13 @@ namespace XHWK.WKTool.Utils
57 68
                 for (int i = startPageNum; i <= endPageNum; i++)
58 69
                 {
59 70
                     imageSaveOptions.PageIndex = i - 1;
60
-                    string savepath = System.IO.Path.Combine(imageOutputPath, imageName) + "_" + i + "." + imageFormat.ToString();
61
-                    doc.Save(savepath, imageSaveOptions);
62
-                    images.Add(savepath);
71
+                    if (imageOutputPath != null)
72
+                    {
73
+                        string savepath = System.IO.Path.Combine(imageOutputPath, imageName) + "_" + i + "." + imageFormat.ToString();
74
+                        doc.Save(savepath, imageSaveOptions);
75
+                        images.Add(savepath);
76
+                    }
63 77
                 }
64
-                imageSaveOptions = null;
65
-                doc = null;
66 78
             }
67 79
             catch (Exception ex)
68 80
             {

+ 68
- 66
XHWK.WKTool/Utils/ZAudioRecordHelper.cs View File

@@ -10,87 +10,86 @@ namespace XHWK.WKTool.Utils
10 10
     {
11 11
         public enum RecordType
12 12
         {
13
-            loudspeaker = 0, // 扬声器
14
-            microphone = 1 //麦克风
13
+            Loudspeaker = 0, // 扬声器
14
+            Microphone = 1 //麦克风
15 15
         }
16 16
 
17 17
         public enum RecordState
18 18
         {
19
-            stop = 0,
20
-            start = 1,
21
-            pause = 2
19
+            Stop = 0,
20
+            Start = 1,
21
+            Pause = 2
22 22
         }
23 23
 
24 24
         //录制的类型
25
-        private RecordType _t = RecordType.microphone;
25
+        private RecordType _t;
26 26
 
27
-        private RecordState _state = RecordState.stop;
27
+        private RecordState _state;
28 28
 
29 29
         //录制麦克风的声音
30
-        private WaveInEvent waveIn = null; //new WaveInEvent();
30
+        private WaveInEvent _waveIn; //new WaveInEvent();
31 31
 
32 32
         //录制扬声器的声音
33
-        private WasapiLoopbackCapture capture = null; //new WasapiLoopbackCapture();
33
+        private WasapiLoopbackCapture _capture; //new WasapiLoopbackCapture();
34 34
 
35 35
         //生成音频文件的对象
36
-        private WaveFileWriter writer = null;
36
+        private WaveFileWriter _writer;
37 37
 
38
-        private string audioFile = "";
38
+        private string _audioFile;
39 39
 
40 40
         public ZAudioRecordHelper(string filePath, RecordType type)
41 41
         {
42 42
             _t = type;
43
-            audioFile = filePath;
44
-            _state = RecordState.pause;
43
+            _audioFile = filePath;
44
+            _state = RecordState.Pause;
45 45
             try
46 46
             {
47
-                if (_t == RecordType.microphone)
47
+                if (_t == RecordType.Microphone)
48 48
                 {
49
-                    waveIn = new WaveInEvent();
50
-                    writer = new WaveFileWriter(audioFile, waveIn.WaveFormat);
49
+                    _waveIn = new WaveInEvent();
50
+                    _writer = new WaveFileWriter(_audioFile, _waveIn.WaveFormat);
51 51
                     //开始录音,写数据
52
-                    waveIn.DataAvailable += (s, a) =>
52
+                    _waveIn.DataAvailable += (s, a) =>
53 53
                     {
54
-                        if (_state == RecordState.start)
54
+                        if (_state == RecordState.Start)
55 55
                         {
56
-                            writer.Write(a.Buffer, 0, a.BytesRecorded);
56
+                            _writer.Write(a.Buffer, 0, a.BytesRecorded);
57 57
                         }
58 58
                     };
59 59
 
60 60
                     //结束录音
61
-                    waveIn.RecordingStopped += (s, a) =>
61
+                    _waveIn.RecordingStopped += (s, a) =>
62 62
                     {
63
-                        writer.Dispose();
64
-                        writer = null;
65
-                        waveIn.Dispose();
63
+                        _writer.Dispose();
64
+                        _writer = null;
65
+                        _waveIn.Dispose();
66 66
                     };
67
-
68
-                    waveIn.StartRecording();
67
+                    _waveIn.StartRecording();
69 68
                 }
70 69
                 else
71 70
                 {
72
-                    capture = new WasapiLoopbackCapture();
73
-                    writer = new WaveFileWriter(audioFile, capture.WaveFormat);
74
-
75
-                    capture.DataAvailable += (s, a) =>
71
+                    _capture = new WasapiLoopbackCapture();
72
+                    _writer = new WaveFileWriter(_audioFile, _capture.WaveFormat);
73
+                    _capture.DataAvailable += (s, a) =>
76 74
                     {
77
-                        if (_state == RecordState.start)
75
+                        if (_state == RecordState.Start)
78 76
                         {
79
-                            writer.Write(a.Buffer, 0, a.BytesRecorded);
77
+                            _writer.Write(a.Buffer, 0, a.BytesRecorded);
80 78
                         }
81 79
                     };
82 80
                     //结束录音
83
-                    capture.RecordingStopped += (s, a) =>
81
+                    _capture.RecordingStopped += (s, a) =>
84 82
                     {
85
-                        writer.Dispose();
86
-                        writer = null;
87
-                        capture.Dispose();
83
+                        _writer.Dispose();
84
+                        _writer = null;
85
+                        _capture.Dispose();
88 86
                     };
89
-                    capture.StartRecording();
87
+                    _capture.StartRecording();
90 88
                 }
91 89
             }
92 90
             catch (Exception)
93 91
             {
92
+                // ignored
94 93
             }
95 94
         }
96 95
 
@@ -99,7 +98,7 @@ namespace XHWK.WKTool.Utils
99 98
         /// </summary>
100 99
         public void StartRecordAudio()
101 100
         {
102
-            _state = RecordState.start;
101
+            _state = RecordState.Start;
103 102
         }
104 103
 
105 104
         /// <summary>
@@ -107,14 +106,14 @@ namespace XHWK.WKTool.Utils
107 106
         /// </summary>
108 107
         public void StopRecordAudio()
109 108
         {
110
-            _state = RecordState.stop;
111
-            if (_t == RecordType.microphone)
109
+            _state = RecordState.Stop;
110
+            if (_t == RecordType.Microphone)
112 111
             {
113
-                waveIn.StopRecording();
112
+                _waveIn.StopRecording();
114 113
             }
115 114
             else
116 115
             {
117
-                capture.StopRecording();
116
+                _capture.StopRecording();
118 117
             }
119 118
         }
120 119
 
@@ -123,7 +122,7 @@ namespace XHWK.WKTool.Utils
123 122
         /// </summary>
124 123
         public void PauseRecordAudio()
125 124
         {
126
-            _state = RecordState.pause;
125
+            _state = RecordState.Pause;
127 126
         }
128 127
 
129 128
         /// <summary>
@@ -131,7 +130,7 @@ namespace XHWK.WKTool.Utils
131 130
         /// </summary>
132 131
         public void ResumeRecordAudio()
133 132
         {
134
-            _state = RecordState.start;
133
+            _state = RecordState.Start;
135 134
         }
136 135
 
137 136
         /// <summary>
@@ -143,15 +142,14 @@ namespace XHWK.WKTool.Utils
143 142
         {
144 143
             string tempPath = Path.GetTempPath();
145 144
             // Console.WriteLine("临时路径:" + tempPath);
146
-            WaveInEvent mWaveIn = null;
145
+            WaveInEvent mWaveIn;
147 146
             WaveFileWriter mWriter = null;
148
-            WasapiLoopbackCapture mCapture = null;
147
+            WasapiLoopbackCapture mCapture;
149 148
             try
150 149
             {
151
-                if (type == RecordType.microphone)
150
+                if (type == RecordType.Microphone)
152 151
                 {
153 152
                     string mAudioFile = Path.Combine(tempPath, "_microphone.mp3");
154
-
155 153
                     mWaveIn = new WaveInEvent();
156 154
                     mWriter = new WaveFileWriter(mAudioFile, mWaveIn.WaveFormat);
157 155
                     //开始录音,写数据
@@ -160,49 +158,54 @@ namespace XHWK.WKTool.Utils
160 158
                     //结束录音
161 159
                     mWaveIn.RecordingStopped += (s, a) =>
162 160
                     {
163
-                        mWriter.Dispose();
161
+                        if (mWriter != null)
162
+                        {
163
+                            mWriter.Dispose();
164
+                        }
164 165
                         mWriter = null;
165 166
                         mWaveIn.Dispose();
166
-
167 167
                         if (File.Exists(mAudioFile))
168 168
                         {
169 169
                             File.Delete(mAudioFile);
170 170
                         }
171 171
                     };
172
-
173 172
                     mWaveIn.StartRecording();
174
-
175
-                    ThreadPool.QueueUserWorkItem(o =>
176
-                    {
177
-                        Thread.Sleep(200);
178
-                        mWaveIn.StopRecording();
179
-                    });
173
+                    ThreadPool.QueueUserWorkItem(
174
+                        o =>
175
+                        {
176
+                            Thread.Sleep(200);
177
+                            mWaveIn.StopRecording();
178
+                        }
179
+                    );
180 180
                 }
181 181
                 else
182 182
                 {
183 183
                     string mAudioFile = Path.Combine(tempPath, "_loudspeaker.mp3");
184 184
                     mCapture = new WasapiLoopbackCapture();
185 185
                     mWriter = new WaveFileWriter(mAudioFile, mCapture.WaveFormat);
186
-
187
-                    mCapture.DataAvailable += (s, a) => { mWriter.Write(a.Buffer, 0, a.BytesRecorded); };
186
+                    mCapture.DataAvailable += (s, a) =>
187
+                    {
188
+                        mWriter?.Write(a.Buffer, 0, a.BytesRecorded);
189
+                    };
188 190
                     //结束录音
189 191
                     mCapture.RecordingStopped += (s, a) =>
190 192
                     {
191
-                        mWriter.Dispose();
193
+                        mWriter?.Dispose();
192 194
                         mWriter = null;
193 195
                         mCapture.Dispose();
194
-
195 196
                         if (File.Exists(mAudioFile))
196 197
                         {
197 198
                             File.Delete(mAudioFile);
198 199
                         }
199 200
                     };
200 201
                     mCapture.StartRecording();
201
-                    ThreadPool.QueueUserWorkItem(o =>
202
-                    {
203
-                        Thread.Sleep(200);
204
-                        mCapture.StopRecording();
205
-                    });
202
+                    ThreadPool.QueueUserWorkItem(
203
+                        o =>
204
+                        {
205
+                            Thread.Sleep(200);
206
+                            mCapture.StopRecording();
207
+                        }
208
+                    );
206 209
                 }
207 210
             }
208 211
             catch (Exception)
@@ -212,7 +215,6 @@ namespace XHWK.WKTool.Utils
212 215
                     mWriter.Dispose();
213 216
                     mWriter = null;
214 217
                 }
215
-
216 218
                 return false;
217 219
             }
218 220
 

XHWK.WKTool/system/ZJClippingBorder.cs → XHWK.WKTool/Utils/ZClippingBorder.cs View File

@@ -5,7 +5,7 @@ using System.Windows.Media;
5 5
 
6 6
 namespace Common.system
7 7
 {
8
-    public class ZJClippingBorder : Border
8
+    public class ZClippingBorder : Border
9 9
     {
10 10
         private object _oldClip;
11 11
 

+ 2
- 2
XHWK.WKTool/Utils/ZConfigAppUtil.cs View File

@@ -74,8 +74,8 @@
74 74
         {
75 75
             SetVaule("ServerIp", "127.0.0.1");
76 76
             SetVaule("ServerPort", "10088");
77
-            Console.WriteLine("ServerIp:" + GetVaule("ServerIp"));
78
-            Console.WriteLine("ServerXXX:" + (GetVaule("ServerXXX") == null));
77
+            Console.WriteLine(@"ServerIp:" + GetVaule("ServerIp"));
78
+            Console.WriteLine(@"ServerXXX:" + (GetVaule("ServerXXX") == null));
79 79
         }
80 80
     }
81 81
 }

XHWK.WKTool/system/ZHttpUtil.cs → XHWK.WKTool/Utils/ZHttpUtil.cs View File


+ 39
- 41
XHWK.WKTool/Utils/ZVideoRecordHelper.cs View File

@@ -18,30 +18,22 @@ namespace XHWK.WKTool.Utils
18 18
             Pause = 2
19 19
         }
20 20
 
21
-        private RecordState _state = RecordState.Stop;
22
-
23
-        private string _filePath;
24
-        private int _width;
25
-        private int _height;
21
+        private RecordState _state;
26 22
 
27 23
         //录制帧率
28
-        private int _rate = 5;
29 24
 
30 25
         //录制质量
31
-        private int _quality = 8;
32 26
 
33
-        private bool _captureMouse = false;
27
+        private bool _captureMouse;
34 28
 
35
-        private VideoFileWriter videoWriter = new VideoFileWriter();//视频写入
36
-        private ScreenCaptureStream videoStreamer;//视频捕获
29
+        private VideoFileWriter _videoWriter = new VideoFileWriter(); //视频写入
30
+        private ScreenCaptureStream _videoStreamer; //视频捕获
37 31
 
38 32
         public ZVideoRecordHelper(string filePath, int width, int height, int rate = 5, int quality = 8, bool captureMouse = false)
39 33
         {
40
-            _filePath = filePath;
41
-            _width = width / 2 * 2;
42
-            _height = height / 2 * 2;
43
-            _rate = rate;
44
-            _quality = quality;
34
+            int width1 = width / 2 * 2;
35
+            int height1 = height / 2 * 2;
36
+            int rate1 = rate;
45 37
             _captureMouse = captureMouse;
46 38
             _state = RecordState.Pause;
47 39
             try
@@ -49,23 +41,28 @@ namespace XHWK.WKTool.Utils
49 41
                 // 打开写入
50 42
                 lock (this)
51 43
                 {
52
-                    videoWriter.Open(
53
-                        _filePath,
54
-                        _width,
55
-                        _height,
56
-                        _rate,
44
+                    _videoWriter.Open(
45
+                        filePath,
46
+                        width1,
47
+                        height1,
48
+                        rate1,
57 49
                         VideoCodec.MPEG4,
58
-                        _width * _height * _quality
50
+                        width1 * height1 * quality
59 51
                     );
60 52
                 }
61
-
62
-                System.Drawing.Rectangle rec = new System.Drawing.Rectangle(0, 0, _width, _height);
63
-                videoStreamer = new ScreenCaptureStream(rec, 1000 / _rate); //帧间隔需要和帧率关联,不然录的10秒视频文件不是10s
64
-                videoStreamer.NewFrame += VideoNewFrame;
65
-                videoStreamer.Start();
53
+                System.Drawing.Rectangle rec = new System.Drawing.Rectangle(
54
+                    0,
55
+                    0,
56
+                    width1,
57
+                    height1
58
+                );
59
+                _videoStreamer = new ScreenCaptureStream(rec, 1000 / rate1); //帧间隔需要和帧率关联,不然录的10秒视频文件不是10s
60
+                _videoStreamer.NewFrame += VideoNewFrame;
61
+                _videoStreamer.Start();
66 62
             }
67 63
             catch (Exception)
68 64
             {
65
+                // ignored
69 66
             }
70 67
         }
71 68
 
@@ -79,22 +76,22 @@ namespace XHWK.WKTool.Utils
79 76
         }
80 77
 
81 78
         [DllImport("user32.dll")]
82
-        private static extern bool GetCursorInfo(out CURSORINFO pci);
79
+        private static extern bool GetCursorInfo(out Cursorinfo pci);
83 80
 
84 81
         [StructLayout(LayoutKind.Sequential)]
85
-        private struct POINT
82
+        private struct Point
86 83
         {
87 84
             public Int32 x;
88 85
             public Int32 y;
89 86
         }
90 87
 
91 88
         [StructLayout(LayoutKind.Sequential)]
92
-        private struct CURSORINFO
89
+        private struct Cursorinfo
93 90
         {
94 91
             public Int32 cbSize;
95 92
             public Int32 flags;
96 93
             public IntPtr hCursor;
97
-            public POINT ptScreenPos;
94
+            public Point ptScreenPos;
98 95
         }
99 96
 
100 97
         // 帧返回时绘制上鼠标
@@ -105,17 +102,15 @@ namespace XHWK.WKTool.Utils
105 102
                 if (_captureMouse)
106 103
                 {
107 104
                     var g = System.Drawing.Graphics.FromImage(e.Frame);
108
-                    CURSORINFO pci;
109
-                    pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
105
+                    Cursorinfo pci;
106
+                    pci.cbSize = Marshal.SizeOf(typeof(Cursorinfo));
110 107
                     GetCursorInfo(out pci);
111 108
                     try
112 109
                     {
113 110
                         System.Windows.Forms.Cursor cur = new System.Windows.Forms.Cursor(pci.hCursor);
114
-                        cur.Draw
115
-                        (
111
+                        cur.Draw(
116 112
                             g,
117
-                            new System.Drawing.Rectangle
118
-                            (
113
+                            new System.Drawing.Rectangle(
119 114
                                 System.Windows.Forms.Cursor.Position.X - 10,
120 115
                                 System.Windows.Forms.Cursor.Position.Y - 10,
121 116
                                 cur.Size.Width,
@@ -123,9 +118,12 @@ namespace XHWK.WKTool.Utils
123 118
                             )
124 119
                         );
125 120
                     }
126
-                    catch { } //打开任务管理器时会导致异常
121
+                    catch
122
+                    {
123
+                        // ignored
124
+                    } //打开任务管理器时会导致异常
127 125
                 }
128
-                videoWriter.WriteVideoFrame(e.Frame);
126
+                _videoWriter.WriteVideoFrame(e.Frame);
129 127
             }
130 128
         }
131 129
 
@@ -136,11 +134,11 @@ namespace XHWK.WKTool.Utils
136 134
         {
137 135
             _state = RecordState.Stop;
138 136
             // 停止
139
-            videoStreamer.Stop();
137
+            _videoStreamer.Stop();
140 138
 
141 139
             //结束写入
142
-            videoWriter.Close();
143
-            videoWriter.Dispose();
140
+            _videoWriter.Close();
141
+            _videoWriter.Dispose();
144 142
         }
145 143
 
146 144
         /// <summary>

XHWK.WKTool/UControl/UC_MultiRangeSlider.xaml → XHWK.WKTool/View/UControl/UC_MultiRangeSlider.xaml View File


XHWK.WKTool/UControl/UC_MultiRangeSlider.xaml.cs → XHWK.WKTool/View/UControl/UC_MultiRangeSlider.xaml.cs View File


XHWK.WKTool/UControl/Uc_VideoItem.xaml → XHWK.WKTool/View/UControl/Uc_VideoItem.xaml View File


XHWK.WKTool/UControl/Uc_VideoItem.xaml.cs → XHWK.WKTool/View/UControl/Uc_VideoItem.xaml.cs View File


+ 29
- 31
XHWK.WKTool/XHWK.WKTool.csproj View File

@@ -239,8 +239,8 @@
239 239
     <Compile Include="CountdownWindow.xaml.cs">
240 240
       <DependentUpon>CountdownWindow.xaml</DependentUpon>
241 241
     </Compile>
242
-    <Compile Include="DAL\DAL_Upload.cs" />
243
-    <Compile Include="DAL\XHApi.cs" />
242
+    <Compile Include="DAL\DalUpload.cs" />
243
+    <Compile Include="DAL\XhApi.cs" />
244 244
     <Compile Include="DAL\ResultVo.cs" />
245 245
     <Compile Include="DeviceWindow.xaml.cs">
246 246
       <DependentUpon>DeviceWindow.xaml</DependentUpon>
@@ -294,7 +294,7 @@
294 294
     <Compile Include="Models\PrintModel.cs" />
295 295
     <Compile Include="Models\ResultVo.cs" />
296 296
     <Compile Include="Models\Tool.cs" />
297
-    <Compile Include="license\MyLicense.cs" />
297
+    <Compile Include="License\MyLicense.cs" />
298 298
     <Compile Include="Models\DownloadInfoModel.cs" />
299 299
     <Compile Include="Models\ViewModel.cs" />
300 300
     <Compile Include="PracticeWindow.xaml.cs">
@@ -310,37 +310,35 @@
310 310
       <DependentUpon>ScreenRecordingToolbarWindow.xaml</DependentUpon>
311 311
     </Compile>
312 312
     <Compile Include="Skin\SkinConfig.cs" />
313
-    <Compile Include="system\AutoStartHelper.cs" />
314
-    <Compile Include="system\BlackboardNew.cs" />
315
-    <Compile Include="system\CameraHelper.cs" />
316
-    <Compile Include="system\CLeopardZip.cs" />
317
-    <Compile Include="system\DataConvertCommon.cs" />
318
-    <Compile Include="system\DataProvider.cs" />
319
-    <Compile Include="system\DownloadManager.cs" />
320
-    <Compile Include="system\DownloadService.cs" />
321
-    <Compile Include="system\FFMpeg.cs" />
322
-    <Compile Include="system\FileToolsCommon.cs" />
323
-    <Compile Include="system\FreeMemoryHelper.cs" />
324
-    <Compile Include="system\ZHttpUtil.cs" />
325
-    <Compile Include="system\ImageHelper.cs" />
326
-    <Compile Include="system\JsonHelper.cs" />
327
-    <Compile Include="system\KeyboardHookCommon.cs" />
328
-    <Compile Include="system\LatticeFileHelper.cs" />
329
-    <Compile Include="system\LogHelper.cs" />
330
-    <Compile Include="system\MouseEventCommon.cs" />
331
-    <Compile Include="system\PdfTrunImage.cs" />
332
-    <Compile Include="system\PrimaryScreen.cs" />
333
-    <Compile Include="system\QueueSync.cs" />
334
-    <Compile Include="system\SplashScreen.cs" />
335
-    <Compile Include="system\XmlUtilHelper.cs" />
336
-    <Compile Include="system\ZJClippingBorder.cs" />
313
+    <Compile Include="Utils\BlackboardNew.cs" />
314
+    <Compile Include="Utils\CameraHelper.cs" />
315
+    <Compile Include="Utils\DataConvertCommon.cs" />
316
+    <Compile Include="Utils\DataProvider.cs" />
317
+    <Compile Include="Utils\DownloadManager.cs" />
318
+    <Compile Include="Utils\DownloadService.cs" />
319
+    <Compile Include="Utils\FFMpeg.cs" />
320
+    <Compile Include="Utils\FileToolsCommon.cs" />
321
+    <Compile Include="Utils\FreeMemoryHelper.cs" />
322
+    <Compile Include="Utils\ZHttpUtil.cs" />
323
+    <Compile Include="Utils\ImageHelper.cs" />
324
+    <Compile Include="Utils\JsonHelper.cs" />
325
+    <Compile Include="Utils\KeyboardHookCommon.cs" />
326
+    <Compile Include="Utils\LatticeFileHelper.cs" />
327
+    <Compile Include="Utils\LogHelper.cs" />
328
+    <Compile Include="Utils\MouseEventCommon.cs" />
329
+    <Compile Include="Utils\PdfTrunImage.cs" />
330
+    <Compile Include="Utils\PrimaryScreen.cs" />
331
+    <Compile Include="Utils\QueueSync.cs" />
332
+    <Compile Include="Utils\SplashScreen.cs" />
333
+    <Compile Include="Utils\XmlUtilHelper.cs" />
334
+    <Compile Include="Utils\ZClippingBorder.cs" />
337 335
     <Compile Include="Utils\ImageOperationUtil.cs" />
338 336
     <Compile Include="Utils\pen\TQLPen\PenEvents.cs" />
339 337
     <Compile Include="Utils\pen\TQLPen\Pentiming.cs" />
340
-    <Compile Include="UControl\UC_MultiRangeSlider.xaml.cs">
338
+    <Compile Include="View\UControl\UC_MultiRangeSlider.xaml.cs">
341 339
       <DependentUpon>UC_MultiRangeSlider.xaml</DependentUpon>
342 340
     </Compile>
343
-    <Compile Include="UControl\Uc_VideoItem.xaml.cs">
341
+    <Compile Include="View\UControl\Uc_VideoItem.xaml.cs">
344 342
       <DependentUpon>Uc_VideoItem.xaml</DependentUpon>
345 343
     </Compile>
346 344
     <Compile Include="UploadWindow.xaml.cs">
@@ -456,11 +454,11 @@
456 454
       <Generator>MSBuild:Compile</Generator>
457 455
       <SubType>Designer</SubType>
458 456
     </Page>
459
-    <Page Include="UControl\UC_MultiRangeSlider.xaml">
457
+    <Page Include="View\UControl\UC_MultiRangeSlider.xaml">
460 458
       <SubType>Designer</SubType>
461 459
       <Generator>MSBuild:Compile</Generator>
462 460
     </Page>
463
-    <Page Include="UControl\Uc_VideoItem.xaml">
461
+    <Page Include="View\UControl\Uc_VideoItem.xaml">
464 462
       <SubType>Designer</SubType>
465 463
       <Generator>MSBuild:Compile</Generator>
466 464
     </Page>

+ 1
- 1
XHWK.WKTool/XHWK.WKTool.csproj.user View File

@@ -1,6 +1,6 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 3
   <PropertyGroup>
4
-    <ProjectView>ShowAllFiles</ProjectView>
4
+    <ProjectView>ProjectFiles</ProjectView>
5 5
   </PropertyGroup>
6 6
 </Project>

+ 0
- 104
XHWK.WKTool/system/SplashScreen.cs View File

@@ -1,104 +0,0 @@
1
-using System;
2
-using System.Reflection;
3
-using System.Threading;
4
-using System.Windows.Forms;
5
-
6
-namespace Common.system
7
-{
8
-    /// <summary>
9
-    /// 解决闪屏  加载等待 
10
-    /// 创建人:赵耀
11
-    /// 创建时间:2018年11月27日
12
-    /// </summary>
13
-    public class SplashScreen
14
-    {
15
-        private static object _obj = new object();
16
-
17
-        private static Form _SplashForm = null;
18
-
19
-        private static Thread _SplashThread = null;
20
-
21
-        private delegate void ChangeFormTextdelegate(string s);
22
-
23
-        public static void Show(Type splashFormType)
24
-        {
25
-            if (_SplashThread != null)
26
-            {
27
-                return;
28
-            }
29
-
30
-            if (splashFormType == null)
31
-            {
32
-                throw (new Exception());
33
-            }
34
-
35
-            _SplashThread = new Thread(new ThreadStart(delegate ()
36
-            {
37
-                CreateInstance(splashFormType);
38
-                Application.Run(_SplashForm);
39
-            }))
40
-            {
41
-                IsBackground = true
42
-            };
43
-            _SplashThread.SetApartmentState(ApartmentState.STA);
44
-            _SplashThread.Start();
45
-        }
46
-
47
-        public static void ChangeTitle(string status)
48
-        {
49
-            ChangeFormTextdelegate de = new ChangeFormTextdelegate(ChangeText);
50
-            _SplashForm.Invoke(de, status);
51
-        }
52
-
53
-
54
-
55
-        public static void Close()
56
-        {
57
-            if (_SplashThread == null || _SplashForm == null)
58
-            {
59
-                return;
60
-            }
61
-
62
-            try
63
-            {
64
-                _SplashForm.Invoke(new MethodInvoker(_SplashForm.Close));
65
-            }
66
-            catch (Exception)
67
-            {
68
-            }
69
-            _SplashThread = null;
70
-            _SplashForm = null;
71
-        }
72
-
73
-        private static void ChangeText(string title)
74
-        {
75
-            _SplashForm.Text = title.ToString();
76
-        }
77
-
78
-
79
-
80
-        private static void CreateInstance(Type FormType)
81
-        {
82
-            if (_SplashForm == null)
83
-            {
84
-                lock (_obj)
85
-                {
86
-                    object obj = FormType.InvokeMember(null,
87
-                                        BindingFlags.DeclaredOnly |
88
-                                        BindingFlags.Public | BindingFlags.NonPublic |
89
-                                        BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);
90
-                    _SplashForm = obj as Form;
91
-                    _SplashForm.TopMost = true;
92
-                    _SplashForm.ShowInTaskbar = false;
93
-                    _SplashForm.BringToFront();
94
-                    _SplashForm.StartPosition = FormStartPosition.CenterScreen;
95
-                    if (_SplashForm == null)
96
-                    {
97
-                        throw (new Exception());
98
-                    }
99
-                }
100
-            }
101
-        }
102
-
103
-    }
104
-}

Loading…
Cancel
Save