RegistFileHelper.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace PacsView3D
  8. {
  9. public class RegistFileHelper
  10. {
  11. public static string ComputerInfofile = "Localinfo.key";
  12. public static string RegistInfofile = "RegistInfo.key";
  13. public static void WriteRegistFile(string info)
  14. {
  15. WriteFile(info, RegistInfofile);
  16. }
  17. public static void WriteComputerInfoFile(string info)
  18. {
  19. WriteFile(info, ComputerInfofile);
  20. }
  21. public static string ReadRegistFile()
  22. {
  23. return ReadFile(RegistInfofile);
  24. }
  25. public static string ReadComputerInfoFile()
  26. {
  27. return ReadFile(ComputerInfofile);
  28. }
  29. public static bool ExistComputerInfofile()
  30. {
  31. return File.Exists(ComputerInfofile);
  32. }
  33. public static bool ExistRegistInfofile()
  34. {
  35. return File.Exists(RegistInfofile);
  36. }
  37. private static void WriteFile(string info, string fileName)
  38. {
  39. try
  40. {
  41. using (StreamWriter sw = new StreamWriter(fileName, false))
  42. {
  43. sw.Write(info);
  44. sw.Close();
  45. }
  46. }
  47. catch (Exception ex)
  48. {
  49. }
  50. }
  51. private static string ReadFile(string fileName)
  52. {
  53. string info = string.Empty;
  54. try
  55. {
  56. using (StreamReader sr = new StreamReader(fileName))
  57. {
  58. info = sr.ReadToEnd();
  59. sr.Close();
  60. }
  61. }
  62. catch (Exception ex)
  63. {
  64. }
  65. return info;
  66. }
  67. }
  68. }