AppSettleTool.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 Azylee.Core.IOUtils.DirUtils;
  9. using Azylee.Core.IOUtils.FileUtils;
  10. using System.Collections.Generic;
  11. using System.IO;
  12. namespace Azylee.Core.AppUtils
  13. {
  14. /// <summary>
  15. /// 客户端定居工具
  16. /// </summary>
  17. public class AppSettleTool
  18. {
  19. /// <summary>
  20. /// 判断是否已定居
  21. /// </summary>
  22. /// <param name="path">定居路径</param>
  23. /// <param name="list">货物清单</param>
  24. /// <returns></returns>
  25. public static bool IsSettle(string path, Dictionary<string, string> list)
  26. {
  27. if (Directory.Exists(path))
  28. {
  29. if (list != null)
  30. {
  31. bool allOk = true;
  32. foreach (var l in list)
  33. {
  34. if (!string.IsNullOrWhiteSpace(l.Value))
  35. allOk &= File.Exists(l.Value);
  36. }
  37. return allOk;
  38. }
  39. else
  40. {
  41. return true;
  42. }
  43. }
  44. return false;
  45. }
  46. /// <summary>
  47. /// 定居
  48. /// </summary>
  49. /// <param name="path">定居路径</param>
  50. /// <param name="list">货物清单</param>
  51. /// <returns></returns>
  52. public static bool Settle(string path, Dictionary<string, string> list)
  53. {
  54. if (DirTool.Create(path))
  55. {
  56. if (list != null)
  57. {
  58. foreach (var l in list)
  59. {
  60. FileTool.Copy(l.Key, l.Value, true);
  61. }
  62. }
  63. }
  64. return IsSettle(path, list);
  65. }
  66. }
  67. }