TestUtil.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (c) Microsoft. All rights reserved.
  2. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace OpenXmlPowerTools
  11. {
  12. public class TestUtil
  13. {
  14. private static bool? s_DeleteTempFiles = null;
  15. public static bool DeleteTempFiles
  16. {
  17. get
  18. {
  19. if (s_DeleteTempFiles != null)
  20. return (bool)s_DeleteTempFiles;
  21. FileInfo donotdelete = new FileInfo("donotdelete.txt");
  22. s_DeleteTempFiles = !donotdelete.Exists;
  23. return (bool)s_DeleteTempFiles;
  24. }
  25. }
  26. private static DirectoryInfo s_TempDir = null;
  27. public static DirectoryInfo TempDir
  28. {
  29. get
  30. {
  31. if (s_TempDir != null)
  32. return s_TempDir;
  33. else
  34. {
  35. var now = DateTime.Now;
  36. var tempDirName = String.Format("Test-{0:00}-{1:00}-{2:00}-{3:00}{4:00}{5:00}", now.Year - 2000, now.Month, now.Day, now.Hour, now.Minute, now.Second);
  37. s_TempDir = new DirectoryInfo(Path.Combine(".", tempDirName));
  38. s_TempDir.Create();
  39. return s_TempDir;
  40. }
  41. }
  42. }
  43. public static void NotePad(string str)
  44. {
  45. var guidName = Guid.NewGuid().ToString().Replace("-", "") + ".txt";
  46. var fi = new FileInfo(Path.Combine(TempDir.FullName, guidName));
  47. File.WriteAllText(fi.FullName, str);
  48. var notepadExe = new FileInfo(@"C:\Program Files (x86)\Notepad++\notepad++.exe");
  49. if (!notepadExe.Exists)
  50. notepadExe = new FileInfo(@"C:\Program Files\Notepad++\notepad++.exe");
  51. if (!notepadExe.Exists)
  52. notepadExe = new FileInfo(@"C:\Windows\System32\notepad.exe");
  53. ExecutableRunner.RunExecutable(notepadExe.FullName, fi.FullName, TempDir.FullName);
  54. }
  55. public static void KDiff3(FileInfo oldFi, FileInfo newFi)
  56. {
  57. var kdiffExe = new FileInfo(@"C:\Program Files (x86)\KDiff3\kdiff3.exe");
  58. var result = ExecutableRunner.RunExecutable(kdiffExe.FullName, oldFi.FullName + " " + newFi.FullName, TempDir.FullName);
  59. }
  60. public static void Explorer(DirectoryInfo di)
  61. {
  62. Process.Start(di.FullName);
  63. }
  64. }
  65. }