RelativePathThread.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using GeekDesk.Constant;
  2. using GeekDesk.Util;
  3. using GeekDesk.ViewModel;
  4. using System;
  5. using System.Collections.ObjectModel;
  6. using System.IO;
  7. using System.Threading;
  8. namespace GeekDesk.MyThread
  9. {
  10. public class RelativePathThread
  11. {
  12. public static void MakeRelativePath()
  13. {
  14. new Thread(() =>
  15. {
  16. try
  17. {
  18. ObservableCollection<MenuInfo> menuList = MainWindow.appData.MenuList;
  19. string myExePath = Constants.APP_DIR + "GeekDesk.exe";
  20. foreach (MenuInfo mi in menuList)
  21. {
  22. ObservableCollection<IconInfo> iconList = mi.IconList;
  23. if (iconList == null) continue;
  24. foreach (IconInfo icon in iconList)
  25. {
  26. if (icon == null) continue;
  27. string relativePath = FileUtil.MakeRelativePath(myExePath, icon.Path);
  28. if (File.Exists(icon.Path)
  29. && !string.IsNullOrEmpty(relativePath)
  30. && !relativePath.Equals(icon.Path))
  31. {
  32. icon.RelativePath_NoWrite = relativePath;
  33. }
  34. }
  35. }
  36. CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
  37. //CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_BAK_PATH);
  38. }
  39. catch (Exception ex)
  40. {
  41. LogUtil.WriteErrorLog(ex, "init相对路径出错!");
  42. }
  43. }).Start();
  44. }
  45. }
  46. }