ConfigParamResxManager.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Collections;
  7. using Muchinfo.PC.Common.Bosn;
  8. namespace Muchinfo.MTPClient.Resources
  9. {
  10. public class ConfigParamResxManager
  11. {
  12. private const string _fileName = "ConfigParameterResx.dll";
  13. public static CommonResx ConfigParamResx { get; set; }
  14. public static void SaveConfigParamResx(Hashtable hastableResx, ulong ver)
  15. {
  16. var resx = new CommonResx() { ResourceHashtable = hastableResx, Version = ver };
  17. string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _fileName);
  18. JsonHelper.SaveData<CommonResx>(path, resx, null, true);
  19. }
  20. public static CommonResx GetConfigParamResx()
  21. {
  22. var resx = new CommonResx() { Version = 0 };
  23. string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _fileName);
  24. if (!File.Exists(path))
  25. return resx;
  26. return JsonHelper.LoadData<CommonResx>(path).FirstOrDefault();
  27. }
  28. public static string ConstDesc(string constKey)
  29. {
  30. if (ConfigParamResx != null && ConfigParamResx.ResourceHashtable != null &&
  31. ConfigParamResx.ResourceHashtable.ContainsKey(constKey))
  32. {
  33. return ConfigParamResx.ResourceHashtable[constKey] as string;
  34. }
  35. else
  36. {
  37. return Client_Resource.ResourceManager.GetString(constKey);
  38. }
  39. }
  40. public static void InitConfigParamResx()
  41. {
  42. ConfigParamResx = GetConfigParamResx();
  43. }
  44. #region 数据存在UserData目录
  45. public static void InitConfigParamResx(string filePath)
  46. {
  47. ConfigParamResx = GetConfigParamResx(filePath);
  48. }
  49. /// <summary>
  50. /// Saves the market RESX.
  51. /// </summary>
  52. /// <param name="hastableResx">The hastable RESX.</param>
  53. /// <param name="ver">The ver.</param>
  54. /// <param name="filePath">The file path.</param>
  55. public static void SaveConfigParamResx(Hashtable hastableResx, ulong ver, string filePath)
  56. {
  57. string path = Path.Combine(filePath, _fileName);
  58. ResxManagerHelper.SaveData(hastableResx, ver, path);
  59. }
  60. /// <summary>
  61. /// Gets the market RESX.
  62. /// </summary>
  63. /// <param name="filePath">The file path.</param>
  64. /// <returns>CommonResx.</returns>
  65. private static CommonResx GetConfigParamResx(string filePath)
  66. {
  67. string path = Path.Combine(filePath, _fileName);
  68. return ResxManagerHelper.GetData(path);
  69. }
  70. #endregion
  71. }
  72. }