Program.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Diagnostics;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.IO;
  8. using System.IO.Compression;
  9. using System.Web;
  10. using System.Drawing;
  11. using TEAMModelOS.SDK.Helper.Common.ColorHelper;
  12. namespace ConsoleApplication
  13. {
  14. class Program
  15. {
  16. static void Main(string[] args)
  17. {
  18. ColorConverter converter = new ColorConverter();
  19. Color color4 = Color.FromArgb(255, 192, 0);
  20. Console.WriteLine(converter.SetLuminanceOff(converter.SetLuminanceMod(color4, 20000), 80000));
  21. for (int i = 0; i <= 10; i++)
  22. {
  23. //converter.SetTint(color4, i * 10000);
  24. // Color color5 = ColorHelper.GetShadeOrTintColor(color4, i * 10000, "Tint");
  25. //Color color6 = ColorHelper.GetShadeOrTintColor(color4, i * 10000, "Shade");
  26. // Color color6 = ColorHelper.applyTint(color4, i * 10000);
  27. //Color color6 = ColorHelper.applyShade(color4, i * 10000);
  28. // Console.WriteLine(ColorTranslator.ToHtml(color5) +" "+ converter.SetTint(color4, i * 10000));
  29. }
  30. var watch = Stopwatch.StartNew();
  31. string originalPath = @"C:\Users\ex1\downloads\Presentation2.pptx";
  32. //Get's the pptx name
  33. string originalFileName = originalPath.Substring(originalPath.LastIndexOf('\\') + 1);
  34. string path = @"C:\Users\ex1\desktop\randomStuffNotANYHAVEBOfDY12723489";
  35. //Image folder location
  36. string imagesPath = @"C:\Users\ex1\Desktop\" + originalFileName.Split('.')[0] + "_img";
  37. File.Copy(originalPath, path + ".pptx");
  38. //Change to .zip
  39. FileInfo f1 = new FileInfo(path + ".pptx");
  40. f1.MoveTo(Path.ChangeExtension(path, ".zip"));
  41. if(!Directory.Exists(imagesPath)){
  42. DirectoryInfo di = Directory.CreateDirectory(imagesPath);
  43. }
  44. //Open zip file
  45. using (ZipArchive zip = ZipFile.Open(path + ".zip", ZipArchiveMode.Update)) {
  46. foreach (ZipArchiveEntry entry in zip.Entries)
  47. {
  48. if (entry.FullName.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase) || (entry.FullName.EndsWith(".png", StringComparison.OrdinalIgnoreCase)))
  49. {
  50. if (Directory.Exists(imagesPath))
  51. {
  52. string[] fileEntries = Directory.GetFiles(imagesPath);
  53. int count = 0;
  54. bool exists = false;
  55. while (count < fileEntries.Length)
  56. {
  57. string last = fileEntries[count].Substring(fileEntries[count].LastIndexOf('\\') + 1);
  58. if (last == entry.Name.ToString())
  59. {
  60. exists = true;
  61. break;
  62. }
  63. count++;
  64. }
  65. if (!exists)
  66. entry.ExtractToFile(Path.Combine(imagesPath, entry.Name));
  67. }
  68. }
  69. }
  70. }
  71. //Change back to .pptx
  72. FileInfo f2 = new FileInfo(path + ".zip");
  73. f2.MoveTo(Path.ChangeExtension(path, ".pptx"));
  74. //Do the read
  75. OpenXMLReader reader = new OpenXMLReader(originalPath);
  76. reader.read();
  77. reader.PresentationObject.getXMLTree().Save(@"C:\Users\ex1\Desktop\out.xml");
  78. //Delete file
  79. File.Delete(path + ".pptx");
  80. Console.WriteLine("\nCompilation time: " + (double)watch.ElapsedMilliseconds/1000 + "s");
  81. Console.WriteLine("Press any key to exit...");
  82. Console.ReadKey();
  83. }
  84. }
  85. }