123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- 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;
- }
- }
- }
|