123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590 |
- using FastReport.Design;
- using FastReport.Design.ToolWindows;
- using System;
- using System.Drawing;
- using System.IO;
- using System.Reflection;
- using System.Web;
- using System.Windows.Forms;
- using FastReport.Cloud.FastReport;
- using System.Threading.Tasks;
- using System.Globalization;
- using System.Collections.Generic;
- namespace FastReport.Utils
- {
- partial class Config
- {
- #region Private Fields
- private const UIStyle DEFAULT_UISTYLE = UIStyleUtils.DefaultStyle;
- private static readonly CultureInfo engCultureInfo = new CultureInfo("en-US");
- private static Export.Email.EmailSettings FEmailSettings = new Export.Email.EmailSettings();
- private static DesignerSettings FDesignerSettings = new DesignerSettings();
- private static bool FSplashScreenEnabled = false;
- private static UIStyle FUIStyle = DEFAULT_UISTYLE;
- private static bool FUseRibbon = false;
- private static bool processEvents = false;
- private static int iconPack = 0;
- private static string saveFolder = "";
- private static bool connectionStringVisible = true;
- private static bool disableHotkeys = false;
- private static bool applyLastFormat = true;
- private static Dictionary<string, Keys> shortcuts = CreateDefaultShortcuts();
- #if COMMUNITY
- private static Image splashScreen;
- private static Image welcomeScreen;
- #endif
- private static StorageService welcomeStorage = new StorageService("Designer,Welcome");
- #endregion Private Fields
- #region Public Properties
- /// <summary>
- /// Gets an english culture information for localization purposes
- /// </summary>
- public static CultureInfo EngCultureInfo
- {
- get { return engCultureInfo; }
- }
- /// <summary>
- /// Gets dictionary of shortcut key.
- /// </summary>
- public static Dictionary<string, Keys> Shortcuts
- {
- get { return shortcuts; }
- internal set { shortcuts = value; }
- }
- /// <summary>
- /// Gets or sets a value indicating whether hotkeys should be disabled.
- /// </summary>
- public static bool DisableHotkeys
- {
- get { return disableHotkeys; }
- set { disableHotkeys = value; }
- }
- /// <summary>
- /// Gets or sets a value indicating saving last formatting should be disabled.
- /// </summary>
- public static bool ApplyLastFormat
- {
- get { return applyLastFormat; }
- set { applyLastFormat = value; }
- }
- /// <summary>
- /// Gets or sets a value indicating that UI library must use high dpi compatible rendering.
- /// </summary>
- /// <remarks>This flag is false by default. Turn it on at the application start if you need
- /// better appearance of custom drawn UI items in high dpi mode. This however may result in
- /// wrong appearance on multi-monitor setup.
- /// /// </remarks>
- public static bool EnableBarHighDpi
- {
- #if MONO
- get; set;
- #else
- get
- {
- return DevComponents.DpiHelper.HighDpiEnabled;
- }
- set
- {
- if (!DevComponents.DpiHelper.HighDpiEnabled)
- DevComponents.DpiHelper.EnableHighDpi();
- }
- #endif
- }
- /// <summary>
- /// Gets or sets the settings for the report designer window.
- /// </summary>
- public static DesignerSettings DesignerSettings
- {
- get { return FDesignerSettings; }
- set { FDesignerSettings = value; }
- }
- /// <summary>
- /// Gets or sets the UI style.
- /// </summary>
- /// <remarks>
- /// This property affects both designer and preview windows.
- /// </remarks>
- public static UIStyle UIStyle
- {
- get { return FUIStyle; }
- set { FUIStyle = value; }
- }
- /// <summary>
- /// Gets or sets a value indicating whether the Ribbon UI should be used
- /// </summary>
- public static bool UseRibbon
- {
- get
- {
- #if COMMUNITY
- return false;
- #else
- return FUseRibbon;
- #endif
- }
- set { FUseRibbon = value; }
- }
- /// <summary>
- /// Gets or sets a value indicating whether the designer window should use the compact menu (Visual Studio - alike).
- /// </summary>
- /// <remarks>
- /// The compact menu is currently supported in WPF only.
- /// </remarks>
- public static bool UseCompactMenu { get; set; }
- /// <summary>
- /// Gets or sets a value indicating of displaying the connection string.
- /// If false, the connection string is hidden from the interface.
- /// </summary>
- public static bool ConnectionStringVisible
- {
- get { return connectionStringVisible; }
- set { connectionStringVisible = value; }
- }
- /// <summary>
- /// Gets or set the current icon pack index. Default is 0 (classic).
- /// </summary>
- /// <remarks>Set this property at the application start.</remarks>
- public static int IconPack
- {
- get { return iconPack; }
- set
- {
- if (value < 0)
- value = 0;
- // increase the number when you add new packs.
- int number_of_packs = 2;
- if (value >= number_of_packs)
- value = number_of_packs - 1;
- iconPack = value;
- }
- }
- /// <summary>
- /// Gets or sets a value indicating whether SplashScreen should be displayed while loading designer
- /// </summary>
- public static bool SplashScreenEnabled
- {
- get { return FSplashScreenEnabled; }
- set { FSplashScreenEnabled = value; }
- }
- /// <summary>
- /// Gets or sets a value indicating whether Welcome window feature enabled.
- /// If false, interface elements associated with the Welcome window will not be visible.
- /// </summary>
- public static bool WelcomeEnabled
- {
- get => welcomeStorage.GetBool("Enabled", true);
- set => welcomeStorage.SetBool("Enabled", value);
- }
- /// <summary>
- /// Gets or sets a value indicating whether Welcome window shoud be displayed on startup
- /// </summary>
- public static bool WelcomeShowOnStartup
- {
- get => welcomeStorage.GetBool("ShowOnStartup", true);
- set => welcomeStorage.SetBool("ShowOnStartup", value);
- }
- /// <summary>
- /// Gets the folder to store auto save files
- /// </summary>
- public static string AutoSaveFolder
- {
- get { return Path.Combine(GetTempFolder(), "FastReport"); }
- }
- /// <summary>
- /// Gets or sets the default folder for SaveFileDialog.
- /// </summary>
- public static string SaveFolder
- {
- get { return saveFolder; }
- set { saveFolder = value; }
- }
- /// <summary>
- /// Gets the autosaved report
- /// </summary>
- public static string AutoSaveFile
- {
- get { return Path.Combine(AutoSaveFolder, "autosave.frx"); }
- }
- /// <summary>
- /// Gets the autosaved report path
- /// </summary>
- public static string AutoSaveFileName
- {
- get { return Path.Combine(AutoSaveFolder, "autosave.txt"); }
- }
- /// <summary>
- /// Is necessary to process abort and some other events in parallel
- /// </summary>
- public static bool ProcessEvents
- {
- get { return processEvents; }
- set { processEvents = value; }
- }
- /// <summary>
- /// Gets a value indicating that the ASP.NET hosting permission level is set to full trust.
- /// </summary>
- public static bool FullTrust
- {
- get
- {
- #if AVALONIA
- return true;
- #else
- return GetCurrentTrustLevel() == AspNetHostingPermissionLevel.Unrestricted;
- #endif
- }
- }
- /// <summary>
- /// Gets or sets a value that determines whether to disable some functionality to run in web mode.
- /// </summary>
- /// <remarks>
- /// Use this property if you use FastReport in ASP.Net. Set this property to <b>true</b> <b>before</b>
- /// you access any FastReport .NET objects.
- /// </remarks>
- public static bool WebMode
- {
- get
- {
- return FWebMode;
- }
- set
- {
- FWebMode = value;
- if (value)
- ReportSettings.ShowProgress = false;
- }
- }
- /// <summary>
- /// Gets or sets the settings for the "Send Email" window.
- /// </summary>
- public static Export.Email.EmailSettings EmailSettings
- {
- get { return FEmailSettings; }
- set { FEmailSettings = value; }
- }
- /// <summary>
- /// Gets or sets a value that determines whether to paint designer surface on a separate (render) thread.
- /// </summary>
- /// <remarks>
- /// Default value is false.
- /// </remarks>
- public static bool AvaloniaPaintOnRenderThread { get; set; } = false;
- #endregion Public Properties
- #region Public Methods
- /// <summary>
- /// Restores the form state from the configuration file.
- /// </summary>
- /// <param name="form">The form to restore.</param>
- /// <remarks>Obsolete. Use either BaseForm.Storage or <see cref="FormStorageService"/>.</remarks>
- [Obsolete]
- public static void RestoreFormState(Form form)
- {
- new FormStorageService(form).RestoreFormState();
- }
- /// <summary>
- /// Saves the form state to the configuration file.
- /// </summary>
- /// <param name="form">The form to save.</param>
- /// <remarks>Obsolete. Use either BaseForm.Storage or <see cref="FormStorageService"/>.</remarks>
- [Obsolete]
- public static void SaveFormState(Form form)
- {
- new FormStorageService(form).SaveFormState();
- }
- static partial void SaveConnectionStringVisible()
- {
- new StorageService("Designer,PropertiesWindow").SetBool("ConnectionStringVisible", ConnectionStringVisible);
- }
- static partial void RestoreConnectionStringVisible()
- {
- ConnectionStringVisible = new StorageService("Designer,PropertiesWindow").GetBool("ConnectionStringVisible", true);
- }
- /// <summary>
- /// Create a dictionary of default keyboard shortcuts.
- /// </summary>
- /// <returns></returns>
- public static Dictionary<string, Keys> CreateDefaultShortcuts()
- {
- Dictionary<string, Keys> result = new Dictionary<string, Keys>
- {
- { "File,Open", Keys.Control | Keys.O },
- { "File,Save", Keys.Control | Keys.S },
- { "File,SaveAs", Keys.Control | Keys.Alt | Keys.S },
- { "File,SaveAll", Keys.Control | Keys.Shift | Keys.S },
- #if !COMMUNITY
- { "File,Preview", Keys.Control | Keys.P },
- #endif
- { "Editing,Undo", Keys.Control | Keys.Z },
- { "Editing,Redo", Keys.Control | Keys.Y },
- { "Editing,Cut", Keys.Control | Keys.X },
- { "Editing,Copy", Keys.Control | Keys.C },
- { "Editing,Paste", Keys.Control | Keys.V },
- { "Editing,NewPage", Keys.Control | Keys.N },
- { "Editing,Find", Keys.Control | Keys.F },
- { "Editing,Replace", Keys.Control | Keys.H },
- { "Editing,SelectAll", Keys.Control | Keys.A },
- { "Help,Contents", Keys.F1 },
- { "Editing,Bold", Keys.Control | Keys.B },
- { "Editing,Italic", Keys.Control | Keys.I },
- { "Editing,Underline", Keys.Control | Keys.U },
- };
- return result;
- }
- #endregion Public Methods
- #region Internal Methods
- internal static void DoEvent()
- {
- if (ProcessEvents && !WebMode)
- {
- System.Windows.Forms.Application.DoEvents();
- }
- }
- #endregion Internal Methods
- #region Private Methods
- private static void LoadPluginsInCurrentFolder()
- {
- var appFolder = ApplicationFolder;
- if (!string.IsNullOrEmpty(appFolder))
- {
- // find all plugin-connector in current directory
- var plugins = Directory.GetFiles(appFolder, "FastReport.Data.*.dll");
- // initialize
- foreach (var pluginName in plugins)
- {
- try
- {
- var assembly = Assembly.LoadFrom(pluginName);
- ProcessAssembly(assembly);
- }
- catch
- {
- }
- }
- }
- }
- /// <summary>
- /// Save default <see cref="Auth.AuthService"/> settings and user tokens.
- /// Is user have to consent to save data, clear the data in the config file.
- /// </summary>
- private static void SaveAuthServiceUser()
- {
- XmlItem xi = FDoc.Root.FindItem("Auth").FindItem("User");
- Auth.AuthService auth = Auth.AuthService.Instance;
- if (auth.IsEnable && auth.CanRefresh)
- {
- xi.ClearProps();
- xi.Clear();
- if (auth.User.RefreshToken != null)
- xi.SetProp("refresh_token", auth.User.RefreshToken);
- if (auth.User.IdToken != null)
- xi.SetProp("id_token", auth.User.IdToken);
- if (auth.User.Token != null)
- xi.SetProp("access_token", auth.User.Token);
- }
- else
- {
- xi.ClearProps();
- xi.Clear();
- }
- }
- /// <summary>
- /// Save default <see cref="Auth.AuthService"/> settings and user tokens.
- /// By default internal use only, it is able to be a public
- /// </summary>
- private static async void RestoreAuthServiceUser()
- {
- XmlItem xi = FDoc.Root.FindItem("Auth").FindItem("User");
- Auth.AuthService auth = Auth.AuthService.Instance;
- if (auth.IsEnable)
- {
- auth.User.Reset();
- auth.User.IdToken = xi.GetProp("id_token");
- auth.User.Token = xi.GetProp("access_token");
- auth.User.RefreshToken = xi.GetProp("refresh_token");
- FRCloudOptions.Instance.ResetBackendHostAndApiKey();
- bool isProgramStart = true;
- try
- {
- await Task.Factory.StartNew(() => auth.ParseTokens(isProgramStart));
- }
- catch
- #if DEBUG
- (Exception ex)
- #endif
- {
- auth.User.Reset();
- }
- }
- }
- #if !AVALONIA
- private static AspNetHostingPermissionLevel GetCurrentTrustLevel()
- {
- foreach (AspNetHostingPermissionLevel trustLevel in
- new AspNetHostingPermissionLevel[] {
- AspNetHostingPermissionLevel.Unrestricted,
- AspNetHostingPermissionLevel.High,
- AspNetHostingPermissionLevel.Medium,
- AspNetHostingPermissionLevel.Low,
- AspNetHostingPermissionLevel.Minimal
- })
- {
- try
- {
- new AspNetHostingPermission(trustLevel).Demand();
- }
- catch (System.Security.SecurityException)
- {
- continue;
- }
- return trustLevel;
- }
- return AspNetHostingPermissionLevel.None;
- }
- #endif
- private static void SaveUIStyle()
- {
- var storage = new StorageService("UIStyleNew");
- storage.SetEnum("Style", UIStyle);
- storage.SetBoolStr("Ribbon", UseRibbon); // compatible with prev versions
- storage.SetInt("IconPack", IconPack);
- storage.SetBool("UseCompactMenu", UseCompactMenu);
- }
- private static void RestoreUIStyle()
- {
- var storage = new StorageService("UIStyleNew");
- UIStyle = storage.GetEnum("Style", DEFAULT_UISTYLE);
- UseRibbon = storage.GetBool("Ribbon", true);
- IconPack = storage.GetInt("IconPack", 1);
- UseCompactMenu = storage.GetBool("UseCompactMenu", true);
- #if AVALONIA
- Application.InitControls();
- Application.InitThemeColors();
- #endif
- }
- private static void SaveUIOptions()
- {
- var storage = new StorageService("UIOptions");
- storage.SetBoolStr("DisableHotkeys", DisableHotkeys); // compatible with prev versions
- storage.SetBool("ApplyLastFormat", ApplyLastFormat);
- Dictionary<string, Keys> defaultShortcut = CreateDefaultShortcuts();
- foreach (var item in shortcuts)
- {
- if (!defaultShortcut.ContainsKey(item.Key) || item.Value != defaultShortcut[item.Key] || FDoc.Root.FindItem("Shortcuts," + item.Key) != null)
- {
- StorageService shortCut = new StorageService("Shortcuts," + item.Key);
- shortCut.SetEnum("Value", item.Value);
- }
- }
- }
- private static void RestoreUIOptions()
- {
- RestoreRightToLeft();
- var storage = new StorageService("UIOptions");
- DisableHotkeys = storage.GetBool("DisableHotkeys", false);
- ApplyLastFormat = storage.GetBool("ApplyLastFormat", true);
- if (Root.Find("Shortcuts") != -1)
- foreach (var item in Root.FindItem("Shortcuts").Items)
- {
- foreach (var subItem in item.Items)
- {
- var shortCut = new StorageService("Shortcuts," + item.Name + "," + subItem.Name);
- shortcuts[item.Name + "," + subItem.Name] = shortCut.GetEnum<Keys>("Value");
- }
- }
- }
- #if !COMMUNITY
- private static void RestoreExportOptions()
- {
- ExportsOptions.GetInstance().RestoreState();
- }
- private static void SaveExportOptions()
- {
- ExportsOptions.GetInstance().SaveState();
- }
- #endif
- #if COMMUNITY
- public static Image SplashScreen
- {
- get
- {
- return splashScreen;
- }
- set
- {
- splashScreen = value;
- }
- }
- public static Image WelcomeScreen
- {
- get
- {
- return welcomeScreen;
- }
- set
- {
- welcomeScreen = value;
- }
- }
- #endif
- #endregion Private Methods
- }
- }
|