Folders.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using FastReport.Utils;
  2. using System;
  3. using System.IO;
  4. namespace WpfDemo
  5. {
  6. internal static class Folders
  7. {
  8. private static string reportsFolder;
  9. public static string ReportsFolder => reportsFolder;
  10. public static string DataFolder => ReportsFolder + @"..\Reports\";
  11. public static string MapsFolder => ReportsFolder + @"..\Maps\";
  12. static Folders()
  13. {
  14. FindReportsFolder();
  15. SetupLocalizationFolder();
  16. }
  17. private static void FindReportsFolder()
  18. {
  19. reportsFolder = "";
  20. string thisFolder = Config.ApplicationFolder;
  21. for (int i = 0; i < 6; i++)
  22. {
  23. string dir = Path.Combine(thisFolder, "Reports.New\\");
  24. if (Directory.Exists(dir))
  25. {
  26. string rep_dir = Path.GetFullPath(dir);
  27. if (File.Exists(Path.Combine(rep_dir, "reports.xml")))
  28. {
  29. reportsFolder = rep_dir;
  30. break;
  31. }
  32. }
  33. thisFolder += @"..\";
  34. }
  35. if (reportsFolder == "")
  36. {
  37. thisFolder = Config.ApplicationFolder;
  38. for (int i = 0; i < 6; i++)
  39. {
  40. string dir = Path.Combine(thisFolder, "Demos\\Reports.New\\");
  41. if (Directory.Exists(dir))
  42. {
  43. string rep_dir = Path.GetFullPath(dir);
  44. if (File.Exists(Path.Combine(rep_dir, "reports.xml")))
  45. {
  46. reportsFolder = rep_dir;
  47. break;
  48. }
  49. }
  50. thisFolder += @"..\";
  51. }
  52. }
  53. if (reportsFolder == "")
  54. throw new Exception("Could not locate the Reports folder.");
  55. }
  56. private static void SetupLocalizationFolder()
  57. {
  58. if (!Directory.Exists(Res.LocaleFolder))
  59. Res.LocaleFolder = Config.ApplicationFolder;
  60. if (!CheckLocalizationFolder(Res.LocaleFolder))
  61. {
  62. string locPath = Path.Combine(Res.LocaleFolder, "Localization");
  63. if (!CheckLocalizationFolder(locPath))
  64. {
  65. locPath = Res.LocaleFolder;
  66. for (int i = 0; i < 6; i++)
  67. {
  68. locPath = Path.Combine(locPath, "..");
  69. string testPath = Path.Combine(locPath, "Localization");
  70. if (CheckLocalizationFolder(testPath))
  71. {
  72. Res.LocaleFolder = testPath;
  73. break;
  74. }
  75. }
  76. }
  77. else
  78. Res.LocaleFolder = locPath;
  79. }
  80. }
  81. private static bool CheckLocalizationFolder(string path)
  82. {
  83. if (Directory.Exists(path))
  84. {
  85. string[] locfiles = Directory.GetFiles(path, "*.frl");
  86. return locfiles.Length > 0;
  87. }
  88. return false;
  89. }
  90. }
  91. }