AppSettleTool.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //************************************************************************
  2. // https://github.com/yuzhengyang
  3. // author: yuzhengyang
  4. // date: 2017.10.12 - 2017.10.12
  5. // desc: 客户端定居工具
  6. // Copyright (c) yuzhengyang. All rights reserved.
  7. //************************************************************************
  8. using System;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using Y.Utils.IOUtils.FileUtils;
  14. using Y.Utils.IOUtils.PathUtils;
  15. namespace Y.Utils.AppUtils
  16. {
  17. /// <summary>
  18. /// 客户端定居工具
  19. /// </summary>
  20. public class AppSettleTool
  21. {
  22. /// <summary>
  23. /// 判断是否已定居
  24. /// </summary>
  25. /// <param name="path">定居路径</param>
  26. /// <param name="list">货物清单</param>
  27. /// <returns></returns>
  28. public static bool IsSettle(string path, Dictionary<string, string> list)
  29. {
  30. if (Directory.Exists(path))
  31. {
  32. if (list != null)
  33. {
  34. bool allOk = true;
  35. foreach (var l in list)
  36. {
  37. if (!string.IsNullOrWhiteSpace(l.Value))
  38. allOk &= File.Exists(l.Value);
  39. }
  40. return allOk;
  41. }
  42. else
  43. {
  44. return true;
  45. }
  46. }
  47. return false;
  48. }
  49. /// <summary>
  50. /// 定居
  51. /// </summary>
  52. /// <param name="path">定居路径</param>
  53. /// <param name="list">货物清单</param>
  54. /// <returns></returns>
  55. public static bool Settle(string path, Dictionary<string, string> list)
  56. {
  57. if (DirTool.Create(path))
  58. {
  59. if (list != null)
  60. {
  61. foreach (var l in list)
  62. {
  63. FileTool.Copy(l.Key, l.Value, true);
  64. }
  65. }
  66. }
  67. return IsSettle(path, list);
  68. }
  69. }
  70. }