private string MakePathRelativeToMCNList(string path) { if (string.IsNullOrEmpty(path)) { return(path); } string file = MacrosSystem.GetInstance().ExpandMacro(path); if (File.Exists(file)) { System.Uri uri1 = new Uri(Path.GetFullPath(file)); System.Uri uri2 = new Uri(MCNCollection.GetInstance().FileDirectory); if (uri2.IsBaseOf(uri1) == false) { // only use relative paths if the file is in a subdirectory of the mcn liit file return(path); } Uri relativeUri = uri2.MakeRelativeUri(uri1); // replace %20 with spaces, etc string decoded = HttpUtility.UrlDecode(relativeUri.OriginalString); return(decoded); } return(path); }
private void saveFileCreateMCNList_FileOk(object sender, CancelEventArgs e) { try { // enable now to ensure binding works correctly dataGridViewMCNList.Enabled = true; // create a new .lst file and validate the buttons using (FileStream fs = new FileStream(saveFileCreateMCNList.FileName, FileMode.Create)) { MCNCollection.GetInstance().FileFullName = saveFileCreateMCNList.FileName; ValidateMCNListButtons(); } dataGridViewMCNList.RowsDefaultCellStyle.BackColor = Color.White; // created new list. popup the add networks dialog AddNetworksDialog(); } catch (System.Exception ex) { Program.Logger.Log(LogSeverity.Error, ex.ToString()); // something went wrong - disable again dataGridViewMCNList.Enabled = false; } }
private void ValidateMCNListButtons() { // set the status of the buttons depending on having a valid mcn list if (MCNCollection.GetInstance().FileFullName == string.Empty) { buttonExport.Enabled = false; buttonExportAndProcess.Enabled = false; buttonAddMCNs.Enabled = false; buttonSaveMCNList.Enabled = false; buttonClearMCNList.Enabled = false; } else { buttonAddMCNs.Enabled = true; buttonSaveMCNList.Enabled = true; buttonClearMCNList.Enabled = true; if (dataGridViewMCNList.RowCount > 1) { buttonExport.Enabled = true; buttonExportAndProcess.Enabled = true; } else { buttonExport.Enabled = false; buttonExportAndProcess.Enabled = true; } } }
private void openFileDialogMCN_FileOk(object sender, CancelEventArgs e) { try { // enable the list here for the binding to work correctly dataGridViewMCNList.Enabled = true; // populate the list using (FileStream fs = new FileStream(openFileDialogMCNList.FileName, FileMode.Open)) { MCNCollection.GetInstance().Deserialise(fs); ValidateMCNListButtons(); } // show it is no-longer disabled dataGridViewMCNList.RowsDefaultCellStyle.BackColor = Color.White; } catch (System.Exception ex) { Program.Logger.Log(LogSeverity.Error, ex.ToString()); // something went wrong - disable again dataGridViewMCNList.Enabled = false; } }
public static MCNCollection GetInstance() { if (Instance == null) { Instance = new MCNCollection(); } return(Instance); }
public int NumSelectedNetworks() { int numSelectedNetworks = 0; foreach (MCN mcn in MCNCollection.GetInstance()) { if (mcn.Use) { ++numSelectedNetworks; } } return(numSelectedNetworks); }
private void buttonSaveMCNList_Click(object sender, EventArgs e) { // save the mcn list try { using (FileStream fs = new FileStream(MCNCollection.GetInstance().FileFullName, FileMode.Create)) { MCNCollection.GetInstance().Serialise(fs); Program.Logger.Log(LogSeverity.GoodNews, "Saved mcn list " + MCNCollection.GetInstance().FileFullName); } } catch (System.Exception ex) { Program.Logger.Log(LogSeverity.Error, "Saving may have failed. Exception caught: " + ex.ToString()); } }
private string GetAbsolutePathExpanded(string path) { path = MacrosSystem.GetInstance().ExpandMacro(path); bool isAbsolute = Path.IsPathRooted(path); if (!isAbsolute) { string newPath = Path.Combine(MCNCollection.GetInstance().FileDirectory, path); newPath = Path.GetFullPath(newPath); return(newPath); } return(path); }
public void Process(bool bExportAndProcess, ProgressChangedEventHandler progressChangedEventHandler, RunWorkerCompletedEventHandler workerCompletedEventHandler) { autoResetEvent = new AutoResetEvent(false); StartTimer = DateTime.Now; foreach (MCN network in MCNCollection.GetInstance()) { network.Processed = false; network.Exported = false; } // fire up a background worker thread to keep the UI responsive BackgroundWorker worker = new BackgroundWorker(); if (bExportAndProcess) { worker.DoWork += new DoWorkEventHandler(worker_DoWorkExportAndProcess); } else { worker.DoWork += new DoWorkEventHandler(worker_DoWorkExport); } // add the default event handlers and the caller defined versions, if valid { worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); if (workerCompletedEventHandler != null) { worker.RunWorkerCompleted += workerCompletedEventHandler; } worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); if (progressChangedEventHandler != null) { worker.ProgressChanged += progressChangedEventHandler; } } worker.WorkerReportsProgress = true; worker.RunWorkerAsync(); }
void AddFiles(string[] files, int majorVersion) { foreach (string file in files) { if (string.IsNullOrEmpty(file)) { continue; } // get the file attributes for file or directory FileAttributes attr = File.GetAttributes(file); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { // only 1 level of recursion needed with SearchOption.AllDirectories string[] subFiles = Directory.GetFiles(file, "*" + MCN.MCNExtension, SearchOption.AllDirectories); AddFiles(subFiles, majorVersion); } else { if (File.Exists(file) == false) { continue; } FileInfo fileInfo = new FileInfo(file); if (false == fileInfo.Extension.Equals(MCN.MCNExtension, StringComparison.CurrentCultureIgnoreCase)) { // not an MCN Program.Logger.Log(LogSeverity.Warning, "skipping " + file + " - not an mcn"); continue; } MCNCollection.GetInstance().Add(file, majorVersion); } } }
public void ExportAll(object sender) { if (!File.Exists(MacrosSystem.GetInstance().ExpandMacro(Settings.GetInstance().MorphemeConnectPath))) { Log.Add(new LogItem(LogSeverity.Error, "cannot find morpheme connect exe " + MacrosSystem.GetInstance().ExpandMacro(Settings.GetInstance().MorphemeConnectPath))); return; } string exportRootPath = MacrosSystem.GetInstance().ExpandMacro(Settings.GetInstance().ExportRootPath); if (!Directory.Exists(exportRootPath)) { try { Directory.CreateDirectory(exportRootPath); } catch (System.Exception ex) { Log.Add(new LogItem(LogSeverity.Error, String.Format("cannot find Export root: {0} ({1})", exportRootPath, ex.Message))); return; } } int index = 0; int count = MCNCollection.GetInstance().Count; // only required for multithreaded export ManualResetEvent[] doneEvents = new ManualResetEvent[count]; Result[] results = new Result[count]; List <MCN> uniqueList = MCNCollection.GetInstance().Distinct().ToList(); if (uniqueList.Count != MCNCollection.GetInstance().Count) { Log.Add(new LogItem(LogSeverity.Warning, "connect exporter skipping duplicate triplet(s) <mcn, asset compiler, mcp>")); } Log.Add(new LogItem(LogSeverity.Info, "morpheme connect started exporting " + uniqueList.Count + " networks...")); MorphemeConnectBatchExportTask batchExporter = new MorphemeConnectBatchExportTask(); // export each network foreach (MCN network in uniqueList) { // currently connect writes to a hard coded log file so we need to disable logging or fix the connect log file issue try { if (!network.Use) { Log.Add(new LogItem(LogSeverity.Info, "connect exporter skipping network at user request: " + network.MCNFileName)); continue; } if (!File.Exists(network.GetMCNPathAbsoluteExpanded())) { Log.Add(new LogItem(LogSeverity.Warning, "connect exporter skipping missing mcn " + network.MCNFileName)); continue; } if (!File.Exists(network.GetMCPPathAbsoluteExpanded())) { Log.Add(new LogItem(LogSeverity.Warning, "connect exporter skipping missing mcp " + network.MCPFileName)); continue; } // create a new Result to monitor when it is done results[index] = new Result(network); string exportPath = MacrosSystem.GetInstance().ExpandMacro(Settings.GetInstance().ExportRootPath); string rootPathAdjustedForNetwork = MacrosSystem.GetInstance().ExpandMacroUsingNetwork(exportPath, network); // create the export directory, if required if (!Directory.Exists(rootPathAdjustedForNetwork)) { Directory.CreateDirectory(rootPathAdjustedForNetwork); Log.Add(new LogItem(LogSeverity.Info, "Created directory: " + rootPathAdjustedForNetwork)); } // add the task batchExporter.AddTask(network, rootPathAdjustedForNetwork); } catch (System.IO.IOException ex) { Log.Add(new LogItem(LogSeverity.Error, ex.ToString())); doneEvents[index].Set(); results[index].Success = false; } catch (System.Exception ex) { Log.Add(new LogItem(LogSeverity.Error, ex.ToString())); doneEvents[index].Set(); results[index].Success = false; } } Result result = new Result(new MCN()); batchExporter.BatchExport(ref result); ParseConnectlogFile(); if (result.Success) { Log.Add(new LogItem(LogSeverity.GoodNews, "exported all networks")); } else { Log.Add(new LogItem(LogSeverity.Error, result.ErrorString)); } }
public void ProcessAll(object sender) { // using a thread pool, fire up all the reuqired asset compilers int index = 0; int numSelectedPlatforms = Settings.GetInstance().NumSelectedPlatforms(); int numSelectedNetworks = MCNCollection.GetInstance().NumSelectedNetworks(); int count = numSelectedPlatforms * numSelectedNetworks; // set up the events to monitor when each task is done ManualResetEvent[] doneEvents = new ManualResetEvent[count]; Result[] results = new Result[count]; // check for duplicates List <MCN> uniqueList = MCNCollection.GetInstance().Distinct().ToList(); if (uniqueList.Count != MCNCollection.GetInstance().Count) { Log.Add(new LogItem(LogSeverity.Warning, "asset processor skipping duplicate triplet(s) <mcn, asset compiler, mcp>")); } int actualNumNetworks = 0; foreach (MCN mcn in uniqueList) { if (mcn.Use) { ++actualNumNetworks; } } Log.Add(new LogItem(LogSeverity.Info, "asset compiler started processing " + actualNumNetworks + " networks on " + numSelectedPlatforms + " platforms...")); // for each platform export all the mcns foreach (PlatformConfiguration platform in Settings.GetInstance().Platforms) { if (platform.UseDuringExport == false) { index++; Log.Add(new LogItem(LogSeverity.Info, "asset processor skipping platform at user request: " + platform.AssetCompilerCustomEXE)); continue; } foreach (MCN network in uniqueList) { try { if (network.Use == false) { index++; Log.Add(new LogItem(LogSeverity.Info, "asset processor skipping network at user request: " + network.MCNFileName)); continue; } // skip over missing mcns, missing mcps if (!File.Exists(network.GetMCNPathAbsoluteExpanded()) || !File.Exists(network.GetMCPPathAbsoluteExpanded()) ) { index++; Log.Add(new LogItem(LogSeverity.Warning, "asset processor skipping missing mcn/mcp " + network.MCNFileName + " " + network.MCPFileName)); continue; } // build up all the paths to generate the asset compiler exe string assetCompilerPath = MacrosSystem.GetInstance().ExpandMacro(Settings.GetInstance().RuntimeSDKRoot); string assetCompilerType = Enum.GetName(typeof(MCN.AssetCompilerType), network.AssetCompiler); string assetCompilerExe = MacrosSystem.GetInstance().ExpandMacro(platform.AssetCompilerCustomEXE); string commandLineOptions = ConstructAssetCompilerOptions(assetCompilerExe, Settings.GetInstance().AssetCompilerCommandLine, network.AssetCompiler, platform); if (!File.Exists(assetCompilerExe)) { Log.Add(new LogItem(LogSeverity.Error, "cannot find asset compiler: " + assetCompilerExe)); continue; } results[index] = new Result(network); // set task to 'not done' doneEvents[index] = new ManualResetEvent(false); // build more paths string rootPathAdjustedForNetwork = MacrosSystem.GetInstance().ExpandMacroUsingNetwork(Settings.GetInstance().ExportRootPath, network); string processSubPath = Path.Combine(rootPathAdjustedForNetwork, MacrosSystem.GetInstance().ExpandMacroUsingNetwork(platform.ProcessPathSubDirectory, network)); if (false == Directory.Exists(processSubPath)) { if (File.Exists(processSubPath)) { Log.Add(new LogItem(LogSeverity.Error, "cannot create directory - file with this name already exists: " + processSubPath)); index++; continue; } Directory.CreateDirectory(processSubPath); // wait for creation while (false == Directory.Exists(processSubPath)) { Thread.Sleep(100); } Log.Add(new LogItem(LogSeverity.Info, "Created directory: " + processSubPath)); } // create the task and send it to the thread pool MorphemeAssetProcessorTask processor = new MorphemeAssetProcessorTask(network, rootPathAdjustedForNetwork, processSubPath, assetCompilerExe, commandLineOptions, doneEvents[index]); // need to keep a local copy as it doesn't appear that the lambda expression below is evaluated on that line Result res = results[index]; ThreadPool.QueueUserWorkItem(o => processor.ThreadPoolCallback(ref res)); // default to true and set to false on errors (see below) network.Processed = true; // finally, increment index (ensure this is the final statement as it is used in the catch below) index++; } catch (System.Exception ex) { Log.Add(new LogItem(LogSeverity.Error, ex.ToString())); doneEvents[index].Set(); results[index].Success = false; } } } try { index = 0; // wait for all the threads to be done foreach (WaitHandle handle in doneEvents) { if (handle != null) { handle.WaitOne(); } if (results[index] != null) { if (results[index].Success) { Log.Add(new LogItem(LogSeverity.GoodNews, "processed " + results[index].Platform + " " + results[index].Network.GetMCNPathAbsoluteExpanded())); } else { Log.Add(new LogItem(LogSeverity.Error, "FAILED " + results[index].Platform + " " + results[index].Network.GetMCNPathAbsoluteExpanded() + " " + results[index].ErrorString)); results[index].Network.Processed = false; } } index++; // update the progress bar if (sender != null) { (sender as BackgroundWorker).ReportProgress(50 + ((50 * index) / count)); } } } catch (System.Exception ex) { Log.Add(new LogItem(LogSeverity.Error, ex.ToString())); } }
private void comboBoxMorphemeVersion_SelectedIndexChanged(object sender, EventArgs e) { // the Product combo box has changed try { ComboBox cb = sender as ComboBox; string newValue = cb.Text; // Leave the euphoria asset compiler in place if (!newValue.Equals(MorphemeVersionSelector.CustomStr)) { if (newValue.Contains("Euphoria") && !MCN.SKUSupportedAssetCompilers.Contains(MCN.AssetCompilerType.Euphoria)) { MCN.SKUSupportedAssetCompilers.Add(MCN.AssetCompilerType.Euphoria); } if (!newValue.Contains("Euphoria") && MCN.SKUSupportedAssetCompilers.Contains(MCN.AssetCompilerType.Euphoria)) { MCN.SKUSupportedAssetCompilers.Remove(MCN.AssetCompilerType.Euphoria); } } // if the new value is the custom selection then allow browsing for connect if (newValue == MorphemeVersionSelector.CustomStr) { textBoxMorphemeConnect.Enabled = true; buttonBrowseConnect.Enabled = true; checkBoxUseDynamicPlugins.Enabled = true; } else { textBoxMorphemeConnect.Enabled = false; buttonBrowseConnect.Enabled = false; checkBoxUseDynamicPlugins.Enabled = false; // version 3.6 introduced dynamic plugins MorphemeVersionSelector.MorphemeVersion version = MorphemeVersionSelector.GetInstance().SelectedVersion; checkBoxUseDynamicPlugins.Checked = !(version.MajorVersion < 3 || (version.MajorVersion == 3 && version.MinorVersion < 6)); } int numModified = 0; foreach (MCN mcn in MCNCollection.GetInstance()) { if (mcn.AssetCompiler == MCN.AssetCompilerType.Euphoria && !MCN.SKUSupportedAssetCompilers.Contains(MCN.AssetCompilerType.Euphoria)) { ++numModified; mcn.AssetCompiler = MCN.AssetCompilerType.NoPhysics; } } if (numModified > 0) { dataGridViewMCNList.Refresh(); } } catch (System.Exception ex) { Program.Logger.Log(LogSeverity.Error, ex.ToString()); } }
private void buttonClear_Click(object sender, EventArgs e) { MCNCollection.GetInstance().Clear(); }
private void dataGridView2_CellValueChanged(object sender, DataGridViewCellEventArgs e) { // check that the mcn and mcp exist try { if (e.RowIndex < 0) { return; } DataGridViewColumn column = dataGridViewMCNList.Columns[e.ColumnIndex]; if (column is DataGridViewTextBoxColumn) { DataGridViewCell cell = dataGridViewMCNList[e.ColumnIndex, e.RowIndex]; if (cell == null) { return; } if (cell.Value == null) { // reset the background colour cell.Style.BackColor = Logger.Color_Info; return; } string file = cell.Value.ToString(); if (string.IsNullOrEmpty(file)) { // reset the background colour cell.Style.BackColor = Logger.Color_Info; return; } // expand any macros in the file file = MacrosSystem.GetInstance().ExpandMacro(file); bool isAbsolute = Path.IsPathRooted(file); if (!isAbsolute) { // it's a relative path. prepend the mcn list path to make it absolute string newPath = Path.Combine(MCNCollection.GetInstance().FileDirectory, file); file = Path.GetFullPath(newPath); } cell.Style.BackColor = Logger.Color_Info; if (!File.Exists(file)) { // cannot find file - show warning cell.Style.BackColor = Logger.Color_Warning; return; } // check the mcn is valid { string MCNFileName = "MCNFileName"; MemberInfo[] info = typeof(MCN).GetMember(MCNFileName); if (info.Length > 0) { if (column.DataPropertyName == MCNFileName) { FileInfo fileInfo = new FileInfo(file); if (false == fileInfo.Extension.Equals(MCN.MCNExtension, StringComparison.CurrentCultureIgnoreCase)) { cell.Style.BackColor = Logger.Color_Warning; return; } } } else { Program.Logger.Log(LogSeverity.Error, "Cannot find member variable " + MCNFileName); } } // check the mcp is valid { string MCPFileName = "MCPFileName"; MemberInfo[] info = typeof(MCN).GetMember(MCPFileName); if (info.Length > 0) { if (column.DataPropertyName == MCPFileName) { FileInfo fileInfo = new FileInfo(file); if (false == fileInfo.Extension.Equals(MCN.MCPExtension, StringComparison.CurrentCultureIgnoreCase)) { cell.Style.BackColor = Logger.Color_Warning; return; } } } else { Program.Logger.Log(LogSeverity.Error, "Cannot find member variable " + MCPFileName); } } } } catch (System.Exception ex) { Program.Logger.Log(LogSeverity.Error, "Exception caught: " + ex.ToString()); } }
void InitCustomComponents() { // create columns in the DataGridViews // data bind, etc // MCN list { // bind to the mcns dataGridViewMCNList.DataSource = MCNCollection.GetInstance(); // Set up the Combo box column data source DataGridViewComboBoxColumn assetCompilerCol = (DataGridViewComboBoxColumn)dataGridViewMCNList.Columns[2]; assetCompilerCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; assetCompilerCol.DataSource = MCN.SKUSupportedAssetCompilers; } // settings { // dataGridViewPlatforms { dataGridViewPlatforms.AutoGenerateColumns = false; dataGridViewPlatforms.DataSource = Settings.GetInstance().Platforms; dataGridViewPlatforms.RowHeadersVisible = false; DataGridViewCheckBoxColumn checkBox = new DataGridViewCheckBoxColumn(); checkBox.DataPropertyName = "UseDuringExport"; checkBox.Name = DataGridViewPlatformNames.Use; dataGridViewPlatforms.Columns.Add(checkBox); #if DEV_ENV_SUPPORT DataGridViewTextBoxColumn nameBox = new DataGridViewTextBoxColumn(); nameBox.DataPropertyName = "Name"; nameBox.Name = DataGridViewPlatformNames.Name; dataGridViewPlatforms.Columns.Add(nameBox); #endif DataGridViewTextBoxColumn processPathBox = new DataGridViewTextBoxColumn(); processPathBox.DataPropertyName = "ProcessPathSubDirectory"; processPathBox.Name = DataGridViewPlatformNames.ProcessPath; processPathBox.ToolTipText = "Sub-folder of the export root where to store the processed networks"; dataGridViewPlatforms.Columns.Add(processPathBox); #if DEV_ENV_SUPPORT DataGridViewTextBoxColumn slnFileBox = new DataGridViewTextBoxColumn(); slnFileBox.DataPropertyName = "SlnPlatform"; slnFileBox.Name = DataGridViewPlatformNames.AssetCompilerSLNFile; dataGridViewPlatforms.Columns.Add(slnFileBox); DataGridViewTextBoxColumn configFileBox = new DataGridViewTextBoxColumn(); configFileBox.DataPropertyName = "ConfigFileBox"; configFileBox.Name = DataGridViewPlatformNames.Config; dataGridViewPlatforms.Columns.Add(configFileBox); DataGridViewColumn col = dataGridViewPlatforms.Columns["build config"]; Array values = Enum.GetValues(typeof(MCN.AssetCompilerType)); foreach (MCN.AssetCompilerType val in values) { DataGridViewButtonColumn buttonBox = new DataGridViewButtonColumn(); buttonBox.Name = Enum.GetName(typeof(MCN.AssetCompilerType), val); dataGridViewPlatforms.Columns.Add(buttonBox); } #endif DataGridViewTextBoxColumn exeName = new DataGridViewTextBoxColumn(); exeName.DataPropertyName = "AssetCompilerCustomEXE"; exeName.Name = DataGridViewPlatformNames.AssetCompilerCustomEXEName; dataGridViewPlatforms.Columns.Add(exeName); DataGridViewCheckBoxColumn kinectCheckBox = new DataGridViewCheckBoxColumn(); kinectCheckBox.DataPropertyName = "UseKinect"; kinectCheckBox.Name = DataGridViewPlatformNames.KinectOption; dataGridViewPlatforms.Columns.Add(kinectCheckBox); DataGridViewCheckBoxColumn moveCheckBox = new DataGridViewCheckBoxColumn(); moveCheckBox.DataPropertyName = "UseMove"; moveCheckBox.Name = DataGridViewPlatformNames.MoveOption; dataGridViewPlatforms.Columns.Add(moveCheckBox); foreach (DataGridViewColumn col in dataGridViewPlatforms.Columns) { col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } } // bind the text boxes textBoxMorphemeConnect.DataBindings.Add("Text", Settings.GetInstance(), "MorphemeConnectPath"); textBoxMorphemeSDKRoot.DataBindings.Add("Text", Settings.GetInstance(), "RuntimeSDKRoot"); textBoxExportPath.DataBindings.Add("Text", Settings.GetInstance(), "ExportRootPath"); textBoxAssetCompilerCommandLine.DataBindings.Add("Text", Settings.GetInstance(), "AssetCompilerCommandLine"); } // bind the log output logItemBindingSource.DataSource = Program.Logger.VisibleList; { MCN.SKUSupportedAssetCompilers.Clear(); foreach (MCN.AssetCompilerType acType in Enum.GetValues(typeof(MCN.AssetCompilerType))) { MCN.SKUSupportedAssetCompilers.Add(acType); } } // bind the product combo box { comboBoxMorphemeVersion.DisplayMember = "Key"; comboBoxMorphemeVersion.ValueMember = "Key"; BindingSource binding = new BindingSource(); binding.DataSource = MorphemeVersionSelector.GetInstance().VersionDictionary; comboBoxMorphemeVersion.DataSource = binding; comboBoxMorphemeVersion.DataBindings.Add("SelectedValue", MorphemeVersionSelector.GetInstance(), "SelectedVersionKey", true, DataSourceUpdateMode.OnPropertyChanged); } { BindingSource binding = new BindingSource(); binding.DataSource = Settings.GetInstance().UseDynamicAssetCompilerPlugins; checkBoxUseDynamicPlugins.DataBindings.Add("Checked", Settings.GetInstance(), "UseDynamicAssetCompilerPlugins"); } }