2
0

CustomAction.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Microsoft.Deployment.WindowsInstaller;
  5. using ICSharpCode.SharpZipLib.BZip2;
  6. using System.IO;
  7. using System.Net;
  8. namespace Setup.CA.DownloadOpenH264
  9. {
  10. public class CustomActions
  11. {
  12. [CustomAction]
  13. public static ActionResult DownloadOpenH264(Session session)
  14. {
  15. session.Log("Begin DownloadOpenH264");
  16. string filename = session.CustomActionData["location"] + @"openh264.dll";
  17. try
  18. {
  19. WebRequest request = HttpWebRequest.Create("http://ciscobinary.openh264.org/openh264-1.8.0-win64.dll.bz2");
  20. using (WebResponse response = request.GetResponse())
  21. {
  22. Stream responseStream = response.GetResponseStream();
  23. BZip2InputStream zisUncompressed = new BZip2InputStream(responseStream);
  24. using (var output = File.Create(filename))
  25. {
  26. var buffer = new byte[2048];
  27. int n;
  28. while ((n = zisUncompressed.Read(buffer, 0, buffer.Length)) > 0)
  29. {
  30. output.Write(buffer, 0, n);
  31. }
  32. }
  33. }
  34. }
  35. catch {
  36. session.Log("Unable to download openh264 codec.");
  37. }
  38. return ActionResult.Success;
  39. }
  40. [CustomAction]
  41. public static ActionResult RemoveOpenH264Binary(Session session)
  42. {
  43. session.Log("Begin RemoveOpenH264Binary");
  44. string filename = session.CustomActionData["location"] + @"openh264.dll";
  45. try
  46. {
  47. // Check if file exists with its full path
  48. if (File.Exists(filename))
  49. {
  50. // If file found, delete it
  51. File.Delete(filename);
  52. session.Log("RemoveOpenH264Binary deleted openh264.dll");
  53. }
  54. }
  55. catch (IOException ioExp)
  56. {
  57. session.Log("RemoveOpenH264Binary can't delete openh264.dll");
  58. }
  59. return ActionResult.Success;
  60. }
  61. }
  62. }