PageRenderTime 58ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/PhyreFly/src/forms/MainForm.cs

https://bitbucket.org/drummertom999/phyreballs
C# | 130 lines | 111 code | 19 blank | 0 comment | 28 complexity | 7a818ddf3ac46a57b32d5dc476aadf5f MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. namespace PhyreFly
  11. {
  12. public partial class MainForm : Form
  13. {
  14. string args_xmlFile = String.Empty;
  15. string args_platform = String.Empty;
  16. AssetProcessAction args_action;
  17. public MainForm(string[] args)
  18. {
  19. InitializeComponent();
  20. PFGlobals.MainWindow = this;
  21. if (args.Length > 0 && File.Exists(args[0]))
  22. {
  23. args_xmlFile = Path.GetFullPath(args[0]);
  24. if (args.Length >= 2)
  25. {
  26. string workingDir = args[1].Replace("\"", "").TrimEnd('\\', '/');
  27. workingDir = Path.GetFullPath(workingDir);
  28. if(Directory.Exists(workingDir))
  29. PFAssetProcessor.WorkingDir = workingDir;
  30. }
  31. if (args.Length >= 3)
  32. args_platform = args[2];
  33. if (args.Length == 4)
  34. {
  35. if (args[3] == "build")
  36. args_action = AssetProcessAction.Build;
  37. else if(args[3] == "rebuild")
  38. args_action = AssetProcessAction.Rebuild;
  39. else if(args[3] == "clean")
  40. args_action = AssetProcessAction.Clean;
  41. }
  42. }
  43. }
  44. private void MainWindow_Load(object sender, EventArgs e)
  45. {
  46. PFGlobals.PhyreEngineSDKRoot = Environment.GetEnvironmentVariable("SCE_PHYRE");
  47. if (PFGlobals.PhyreEngineSDKRoot == null)
  48. {
  49. MessageBox.Show("Please make sure the SCE_PHYRE is set and try again");
  50. Close();
  51. }
  52. if(args_xmlFile != String.Empty)
  53. BeginSession(args_xmlFile, args_platform, args_action);
  54. }
  55. private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
  56. {
  57. if (PFAssetProcessor.IsWorking)
  58. {
  59. PFConsole.WriteLine(PFConsole.Severity.ERROR, "Busy, please wait...");
  60. e.Cancel = true;
  61. }
  62. }
  63. #region Drag & Drop Logic
  64. private void MainWindow_DragEnter(object sender, DragEventArgs e)
  65. {
  66. if (m_bIsFileLoaded)
  67. return;
  68. ui_lbl_multiple.Visible = ui_lbl_good.Visible = ui_lbl_xml.Visible = false;
  69. e.Effect = DragDropEffects.None;
  70. if (!e.Data.GetDataPresent(DataFormats.FileDrop))
  71. return;
  72. string[] filePaths = (string[])(e.Data.GetData(DataFormats.FileDrop));
  73. if (filePaths.Length > 1)
  74. {
  75. ui_lbl_multiple.Visible = true;
  76. return;
  77. }
  78. if (Path.GetExtension(filePaths[0]).ToUpper() != ".XML")
  79. {
  80. ui_lbl_xml.Visible = true;
  81. return;
  82. }
  83. ui_lbl_good.Visible = true;
  84. ui_lbl_good.Text = String.Format("{0} Looks Good :)", Path.GetFileName(filePaths[0]));
  85. e.Effect = DragDropEffects.Copy;
  86. }
  87. private void MainWindow_DragDrop(object sender, DragEventArgs e)
  88. {
  89. if (!e.Data.GetDataPresent(DataFormats.FileDrop) || m_bIsFileLoaded)
  90. return;
  91. string[] filePaths = (string[])(e.Data.GetData(DataFormats.FileDrop));
  92. if(filePaths.Length > 1)
  93. return;
  94. BeginSession(filePaths[0], null, AssetProcessAction.None);
  95. }
  96. private void MainWindow_DragLeave(object sender, EventArgs e)
  97. {
  98. ui_lbl_multiple.Visible = ui_lbl_good.Visible = ui_lbl_xml.Visible = false;
  99. }
  100. #endregion
  101. private void BeginSession(string filePath, string platform, AssetProcessAction action)
  102. {
  103. Controls.Clear();
  104. Controls.Add(new AssetManager(filePath, platform, action));
  105. m_bIsFileLoaded = true;
  106. MaximumSize = Size.Empty;
  107. MaximizeBox = true;
  108. }
  109. private bool m_bIsFileLoaded = false;
  110. }
  111. }