using FastReport.Utils; using System; using System.IO; namespace WpfDemo { internal static class Folders { private static string reportsFolder; public static string ReportsFolder => reportsFolder; public static string DataFolder => ReportsFolder + @"..\Reports\"; public static string MapsFolder => ReportsFolder + @"..\Maps\"; static Folders() { FindReportsFolder(); SetupLocalizationFolder(); } private static void FindReportsFolder() { reportsFolder = ""; string thisFolder = Config.ApplicationFolder; for (int i = 0; i < 6; i++) { string dir = Path.Combine(thisFolder, "Reports.New\\"); if (Directory.Exists(dir)) { string rep_dir = Path.GetFullPath(dir); if (File.Exists(Path.Combine(rep_dir, "reports.xml"))) { reportsFolder = rep_dir; break; } } thisFolder += @"..\"; } if (reportsFolder == "") { thisFolder = Config.ApplicationFolder; for (int i = 0; i < 6; i++) { string dir = Path.Combine(thisFolder, "Demos\\Reports.New\\"); if (Directory.Exists(dir)) { string rep_dir = Path.GetFullPath(dir); if (File.Exists(Path.Combine(rep_dir, "reports.xml"))) { reportsFolder = rep_dir; break; } } thisFolder += @"..\"; } } if (reportsFolder == "") throw new Exception("Could not locate the Reports folder."); } private static void SetupLocalizationFolder() { if (!Directory.Exists(Res.LocaleFolder)) Res.LocaleFolder = Config.ApplicationFolder; if (!CheckLocalizationFolder(Res.LocaleFolder)) { string locPath = Path.Combine(Res.LocaleFolder, "Localization"); if (!CheckLocalizationFolder(locPath)) { locPath = Res.LocaleFolder; for (int i = 0; i < 6; i++) { locPath = Path.Combine(locPath, ".."); string testPath = Path.Combine(locPath, "Localization"); if (CheckLocalizationFolder(testPath)) { Res.LocaleFolder = testPath; break; } } } else Res.LocaleFolder = locPath; } } private static bool CheckLocalizationFolder(string path) { if (Directory.Exists(path)) { string[] locfiles = Directory.GetFiles(path, "*.frl"); return locfiles.Length > 0; } return false; } } }