public ImportedGeometryManager() { InitializeComponent(); _correctColor = dataGridView.BackColor.MixWith(Color.LimeGreen, 0.55); _wrongColor = dataGridView.BackColor.MixWith(Color.DarkRed, 0.55); dataGridView.CellMouseDoubleClick += dataGridView_CellMouseDoubleClick; // Initialize sound path data grid view dataGridViewControls.DataGridView = dataGridView; dataGridViewControls.Enabled = true; dataGridViewControls.CreateNewRow = delegate { List <string> paths = LevelFileDialog.BrowseFiles(this, null, PathC.GetDirectoryNameTry(LevelSettings.LevelFilePath), "Select 3D files that you want to see imported.", ImportedGeometry.FileExtensions).ToList(); // Load imported geometries var importInfos = new List <KeyValuePair <ImportedGeometry, ImportedGeometryInfo> >(); foreach (string path in paths) { using (var settingsDialog = new GeometryIOSettingsDialog(new IOGeometrySettings())) { settingsDialog.AddPreset(IOSettingsPresets.GeometryImportSettingsPresets); settingsDialog.SelectPreset("Normal scale to TR scale"); if (settingsDialog.ShowDialog(this) == DialogResult.Cancel) { continue; } var info = new ImportedGeometryInfo(LevelSettings.MakeRelative(path, VariableType.LevelDirectory), settingsDialog.Settings); importInfos.Add(new KeyValuePair <ImportedGeometry, ImportedGeometryInfo>(new ImportedGeometry(), info)); } } LevelSettings.ImportedGeometryUpdate(importInfos); LevelSettings.ImportedGeometries.AddRange(importInfos.Select(entry => entry.Key)); return(importInfos.Select(entry => new ImportedGeometryWrapper(this, entry.Key))); }; dataGridView.DataSource = _dataGridViewDataSource; dataGridViewControls.DeleteRowCheckIfCancel = MessageUserAboutHimDeletingRows; _dataGridViewDataSource.ListChanged += delegate(object sender, ListChangedEventArgs e) { switch (e.ListChangedType) { case ListChangedType.ItemDeleted: var remainingElements = new HashSet <ImportedGeometry>(_dataGridViewDataSource.Select(wrapper => wrapper.Object)); LevelSettings.ImportedGeometries.RemoveAll(obj => !remainingElements.Contains(obj)); // Don't use indices here, the wrapper indices might not match with the real object if sorting was enabled. break; } }; Enabled = true; }
protected string GetTexturePath(string baseDirectory, Texture texture) { var texturePath = _getTexturePathCallback(texture); var relativeTexturePath = PathC.GetRelativePath(baseDirectory, texturePath); if (relativeTexturePath == null || relativeTexturePath == "") { return(texturePath); } return(relativeTexturePath); }
private void ReplaceAllBonesFromFile() { var boneCount = _bones.Count; using (FileDialog dialog = new OpenFileDialog()) { dialog.InitialDirectory = PathC.GetDirectoryNameTry(_tool.DestinationWad.FileName); dialog.FileName = PathC.GetFileNameTry(_tool.DestinationWad.FileName); dialog.Filter = BaseGeometryImporter.FileExtensions.GetFilter(); dialog.Title = "Select a 3D file that you want to see imported."; if (dialog.ShowDialog(this) != DialogResult.OK) { return; } using (var form = new GeometryIOSettingsDialog(new IOGeometrySettings())) { form.AddPreset(IOSettingsPresets.GeometryImportSettingsPresets); if (form.ShowDialog(this) != DialogResult.OK) { return; } var meshes = WadMesh.ImportFromExternalModel(dialog.FileName, form.Settings, false); if (meshes == null || meshes.Count == 0) { ImportFailed(); return; } int meshCount; if (meshes.Count > _bones.Count) { meshCount = _bones.Count; popup.ShowError(panelRendering, "Mesh count is higher in imported model. Only first " + _bones.Count + " will be imported."); } else if (meshes.Count < _bones.Count) { meshCount = meshes.Count; popup.ShowError(panelRendering, "Mesh count is lower in imported model. Only meshes up to " + meshes.Count + " will be replaced."); } else { meshCount = _bones.Count; } for (int i = 0; i < meshCount; i++) { ReplaceExistingBone(meshes[i], _bones[i]); } } } }
public ImportedGeometryInfo(string path, IOGeometrySettings settings) { Name = PathC.GetFileNameWithoutExtensionTry(path); Path = path; Scale = settings.Scale; SwapXY = settings.SwapXY; SwapXZ = settings.SwapXZ; SwapYZ = settings.SwapYZ; InvertFaces = settings.InvertFaces; FlipX = settings.FlipX; FlipY = settings.FlipY; FlipZ = settings.FlipZ; FlipUV_V = settings.FlipUV_V; }
public string GetTRNGVersion() { var buffer = PathC.GetDirectoryNameTry(_level.Settings.MakeAbsolute(_level.Settings.GameExecutableFilePath)) + "\\Tomb_NextGeneration.dll"; if (File.Exists(buffer)) { buffer = (FileVersionInfo.GetVersionInfo(buffer)).ProductVersion; _progressReporter.ReportInfo("TRNG found, version is " + buffer); } else { buffer = "1,3,0,6"; _progressReporter.ReportWarn("Tomb_NextGeneration.dll wasn't found in game directory. Probably you're using TRNG target on vanilla TR4/TRLE?"); } return(buffer); }
protected override void OnPaint(PaintEventArgs e) { LevelSettings settings = _editor?.Level?.Settings; if (settings == null) { return; } if (settings.ImportedGeometries.All(geo => geo.LoadException != null)) { ImportedGeometry errorGeo = settings.ImportedGeometries.FirstOrDefault(geo => geo.LoadException != null); string notifyMessage; if (errorGeo == null) { notifyMessage = "Click here to load new imported geometry."; } else { string filePath = settings.MakeAbsolute(errorGeo.Info.Path); string fileName = PathC.GetFileNameWithoutExtensionTry(filePath) ?? ""; if (PathC.IsFileNotFoundException(errorGeo.LoadException)) { notifyMessage = "Geometry file '" + fileName + "' was not found!\n"; } else { notifyMessage = "Unable to load geometry from file '" + fileName + "'.\n"; } notifyMessage += "Click here to choose a replacement.\n\n"; notifyMessage += "Path: " + (filePath ?? ""); } e.Graphics.Clear(Parent.BackColor); using (var b = new SolidBrush(Colors.DisabledText)) e.Graphics.DrawString(notifyMessage, Font, b, ClientRectangle, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Colors.GreySelection, ButtonBorderStyle.Solid); } else { base.OnPaint(e); } }
private void butImportMeshFromFile_Click(object sender, EventArgs e) { using (FileDialog dialog = new OpenFileDialog()) { dialog.InitialDirectory = PathC.GetDirectoryNameTry(_tool.DestinationWad.FileName); dialog.FileName = PathC.GetFileNameTry(_tool.DestinationWad.FileName); dialog.Filter = BaseGeometryImporter.FileExtensions.GetFilter(); dialog.Title = "Select a 3D file that you want to see imported."; if (dialog.ShowDialog(this) != DialogResult.OK) { return; } using (var form = new GeometryIOSettingsDialog(new IOGeometrySettings())) { form.AddPreset(IOSettingsPresets.GeometryImportSettingsPresets); if (form.ShowDialog(this) != DialogResult.OK) { return; } var mesh = WadMesh.ImportFromExternalModel(dialog.FileName, form.Settings); if (mesh == null) { DarkMessageBox.Show(this, "Error while loading 3D model. Check that the file format \n" + "is supported, meshes are textured and texture file is present.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _workingStatic.Mesh = mesh; _workingStatic.VisibilityBox = _workingStatic.Mesh.CalculateBoundingBox(panelRendering.GizmoTransform); _workingStatic.CollisionBox = _workingStatic.Mesh.CalculateBoundingBox(panelRendering.GizmoTransform); _workingStatic.Version = DataVersion.GetNext(); _workingStatic.Mesh.CalculateNormals(); panelRendering.Invalidate(); UpdatePositionUI(); UpdateCollisionBoxUI(); UpdateVisibilityBoxUI(); UpdateLightUI(); } } }
private void AddChildBoneFromFile() { if (treeSkeleton.SelectedNodes.Count == 0) { return; } var theNode = (WadMeshBoneNode)treeSkeleton.SelectedNodes[0].Tag; using (FileDialog dialog = new OpenFileDialog()) { dialog.InitialDirectory = PathC.GetDirectoryNameTry(_tool.DestinationWad.FileName); dialog.FileName = PathC.GetFileNameTry(_tool.DestinationWad.FileName); dialog.Filter = BaseGeometryImporter.FileExtensions.GetFilter(); dialog.Title = "Select a 3D file that you want to see imported."; if (dialog.ShowDialog(this) != DialogResult.OK) { return; } using (var form = new GeometryIOSettingsDialog(new IOGeometrySettings())) { form.AddPreset(IOSettingsPresets.GeometryImportSettingsPresets); if (form.ShowDialog(this) != DialogResult.OK) { return; } var mesh = WadMesh.ImportFromExternalModel(dialog.FileName, form.Settings); if (mesh == null) { ImportFailed(); return; } InsertNewBone(mesh, theNode); } } }
public string MakeRelative(string path, VariableType baseDirType) { if (string.IsNullOrEmpty(path)) { return(null); } try { if (string.IsNullOrEmpty(LevelFilePath)) { return(Path.GetFullPath(path)); } switch (baseDirType) { case VariableType.EditorDirectory: case VariableType.GameDirectory: case VariableType.LevelDirectory: case VariableType.ScriptDirectory: string relativePath = PathC.GetRelativePath(GetVariable(baseDirType), path); if (relativePath == null) { return(Path.GetFullPath(path)); } return(VariableCreate(baseDirType) + Path.DirectorySeparatorChar + relativePath); default: return(path); } } catch { return(path); } }
public string GetVariable(VariableType type) { string result; switch (type) { case VariableType.EditorDirectory: result = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); break; case VariableType.ScriptDirectory: result = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Dir + "Script"; break; case VariableType.LevelDirectory: if (!string.IsNullOrEmpty(LevelFilePath)) { result = Path.GetDirectoryName(LevelFilePath); } else { result = GetVariable(VariableType.EditorDirectory); } break; case VariableType.GameDirectory: result = MakeAbsolute(GameDirectory ?? VariableCreate(VariableType.LevelDirectory), VariableType.GameDirectory); break; case VariableType.LevelName: if (!string.IsNullOrEmpty(LevelFilePath)) { result = PathC.GetFileNameWithoutExtensionTry(LevelFilePath); } else if (Wads.Count > 0 && !string.IsNullOrEmpty(Wads[0].Path)) { result = PathC.GetFileNameWithoutExtensionTry(Wads[0].Path); } else { result = "Default"; } break; case VariableType.EngineVersion: result = GameVersion.ToString(); break; case VariableType.SoundEngineVersion: result = (GameVersion.Native()).ToString(); break; default: throw new ArgumentException(); } if (result == null) { result = ""; } return(result); }
private void EditorEventRaised(IEditorEvent obj) { // Gray out menu options that do not apply if (obj is Editor.SelectedObjectChangedEvent || obj is Editor.ModeChangedEvent || obj is Editor.SelectedSectorsChangedEvent) { ObjectInstance selectedObject = _editor.SelectedObject; bool enableCutCopy = _editor.Mode == EditorMode.Map2D || selectedObject is PositionBasedObjectInstance || _editor.SelectedSectors.Valid; copyToolStripMenuItem.Enabled = enableCutCopy; cutToolStripMenuItem.Enabled = enableCutCopy; deleteToolStripMenuItem.Enabled = _editor.Mode == EditorMode.Map2D || selectedObject != null; stampToolStripMenuItem.Enabled = selectedObject is PositionBasedObjectInstance; if (obj is Editor.ModeChangedEvent) { ClipboardEvents_ClipboardChanged(this, EventArgs.Empty); } bookmarkObjectToolStripMenuItem.Enabled = selectedObject != null; splitSectorObjectOnSelectionToolStripMenuItem.Enabled = selectedObject is SectorBasedObjectInstance && _editor.SelectedSectors.Valid; } // Disable version-specific controls if (obj is Editor.InitEvent || obj is Editor.GameVersionChangedEvent || obj is Editor.LevelChangedEvent) { addFlybyCameraToolStripMenuItem.Enabled = _editor.Level.Settings.GameVersion >= TRVersion.Game.TR4; addBoxVolumeToolStripMenuItem.Enabled = _editor.Level.Settings.GameVersion == TRVersion.Game.TR5Main; } if (obj is Editor.UndoStackChangedEvent) { var stackEvent = (Editor.UndoStackChangedEvent)obj; undoToolStripMenuItem.Enabled = stackEvent.UndoPossible; redoToolStripMenuItem.Enabled = stackEvent.RedoPossible; } if (obj is Editor.SelectedSectorsChangedEvent) { bool validSectorSelection = _editor.SelectedSectors.Valid; smoothRandomCeilingDownToolStripMenuItem.Enabled = validSectorSelection; smoothRandomCeilingUpToolStripMenuItem.Enabled = validSectorSelection; smoothRandomFloorDownToolStripMenuItem.Enabled = validSectorSelection; smoothRandomFloorUpToolStripMenuItem.Enabled = validSectorSelection; sharpRandomCeilingDownToolStripMenuItem.Enabled = validSectorSelection; sharpRandomCeilingUpToolStripMenuItem.Enabled = validSectorSelection; sharpRandomFloorDownToolStripMenuItem.Enabled = validSectorSelection; sharpRandomFloorUpToolStripMenuItem.Enabled = validSectorSelection; averageCeilingToolStripMenuItem.Enabled = validSectorSelection; averageFloorToolStripMenuItem.Enabled = validSectorSelection; gridWallsIn3ToolStripMenuItem.Enabled = validSectorSelection; gridWallsIn5ToolStripMenuItem.Enabled = validSectorSelection; gridWallsIn3SquaresToolStripMenuItem.Enabled = validSectorSelection; gridWallsIn5SquaresToolStripMenuItem.Enabled = validSectorSelection; splitSectorObjectOnSelectionToolStripMenuItem.Enabled = _editor.SelectedObject is SectorBasedObjectInstance && validSectorSelection; } // Update version-specific controls if (obj is Editor.InitEvent || obj is Editor.LevelChangedEvent || obj is Editor.GameVersionChangedEvent) { bool isNG = _editor.Level.Settings.GameVersion == TRVersion.Game.TRNG; bool isT5M = _editor.Level.Settings.GameVersion == TRVersion.Game.TR5Main; addSphereVolumeToolStripMenuItem.Enabled = isT5M; addPrismVolumeToolStripMenuItem.Enabled = isT5M; addBoxVolumeToolStripMenuItem.Enabled = isT5M; makeQuickItemGroupToolStripMenuItem.Enabled = isNG; } // Update compilation statistics if (obj is Editor.LevelCompilationCompletedEvent) { var evt = obj as Editor.LevelCompilationCompletedEvent; statusLastCompilation.Text = "Last level output { " + evt.InfoString + " }"; } // Update autosave status if (obj is Editor.AutosaveEvent) { var evt = obj as Editor.AutosaveEvent; statusAutosave.Text = evt.Exception == null ? "Autosave OK: " + evt.Time : "Autosave failed!"; statusAutosave.ForeColor = evt.Exception == null ? statusLastCompilation.ForeColor : Color.LightSalmon; } // Update room information on the status strip if (obj is Editor.SelectedRoomChangedEvent || _editor.IsSelectedRoomEvent(obj as Editor.RoomGeometryChangedEvent) || _editor.IsSelectedRoomEvent(obj as Editor.RoomSectorPropertiesChangedEvent) || obj is Editor.RoomPropertiesChangedEvent) { var room = _editor.SelectedRoom; if (room == null) { statusStripSelectedRoom.Text = "Selected room: None"; } else { statusStripSelectedRoom.Text = "Selected room: " + "Name = " + room + " | " + "Pos = (" + room.Position.X + ", " + room.Position.Y + ", " + room.Position.Z + ") | " + "Floor = " + (room.Position.Y + room.GetLowestCorner()) + " | " + "Ceiling = " + (room.Position.Y + room.GetHighestCorner()); } } // Update selection information of the status strip if (obj is Editor.SelectedRoomChangedEvent || _editor.IsSelectedRoomEvent(obj as Editor.RoomGeometryChangedEvent) || _editor.IsSelectedRoomEvent(obj as Editor.RoomSectorPropertiesChangedEvent) || obj is Editor.SelectedSectorsChangedEvent) { var room = _editor.SelectedRoom; if (room == null || !_editor.SelectedSectors.Valid) { statusStripGlobalSelectionArea.Text = "Global area: None"; statusStripLocalSelectionArea.Text = "Local area: None"; } else { int minHeight = room.GetLowestCorner(_editor.SelectedSectors.Area); int maxHeight = room.GetHighestCorner(_editor.SelectedSectors.Area); statusStripGlobalSelectionArea.Text = "Global area = " + "(" + (room.Position.X + _editor.SelectedSectors.Area.X0) + ", " + (room.Position.Z + _editor.SelectedSectors.Area.Y0) + ") \u2192 " + "(" + (room.Position.X + _editor.SelectedSectors.Area.X1) + ", " + (room.Position.Z + _editor.SelectedSectors.Area.Y1) + ")" + " | y = [" + (minHeight == int.MaxValue || maxHeight == int.MinValue ? "N/A" : room.Position.Y + minHeight + ", " + (room.Position.Y + maxHeight)) + "]"; statusStripLocalSelectionArea.Text = "Local area = " + "(" + _editor.SelectedSectors.Area.X0 + ", " + _editor.SelectedSectors.Area.Y0 + ") \u2192 " + "(" + _editor.SelectedSectors.Area.X1 + ", " + _editor.SelectedSectors.Area.Y1 + ")" + " | y = [" + (minHeight == int.MaxValue || maxHeight == int.MinValue ? "N/A" : minHeight + ", " + maxHeight) + "]"; } } // Update application title bar if (obj is Editor.LevelFileNameChangedEvent || obj is Editor.HasUnsavedChangesChangedEvent) { string LevelName = string.IsNullOrEmpty(_editor.Level.Settings.LevelFilePath) ? "Untitled" : PathC.GetFileNameWithoutExtensionTry(_editor.Level.Settings.LevelFilePath); Text = "Tomb Editor " + Application.ProductVersion + " - " + LevelName + (_editor.HasUnsavedChanges ? "*" : ""); } // Update save button if (obj is Editor.HasUnsavedChangesChangedEvent) { saveLevelToolStripMenuItem.Enabled = _editor.HasUnsavedChanges; } // Reload window layout and keyboard shortcuts if the configuration changed if (obj is Editor.ConfigurationChangedEvent) { var e = (Editor.ConfigurationChangedEvent)obj; if (e.UpdateKeyboardShortcuts) { GenerateMenusRecursive(menuStrip.Items, true); } if (e.UpdateLayout) { LoadWindowLayout(_editor.Configuration); } UpdateUIColours(); UpdateControls(); } // Update texture controls if (obj is Editor.LoadedTexturesChangedEvent) { remapTextureToolStripMenuItem.Enabled = removeTexturesToolStripMenuItem.Enabled = unloadTexturesToolStripMenuItem.Enabled = reloadTexturesToolStripMenuItem.Enabled = importConvertTexturesToPng.Enabled = _editor.Level.Settings.Textures.Count > 0; } // Update wad controls if (obj is Editor.LoadedWadsChangedEvent) { removeWadsToolStripMenuItem.Enabled = reloadWadsToolStripMenuItem.Enabled = _editor.Level.Settings.Wads.Count > 0; } if (obj is Editor.LoadedSoundsCatalogsChangedEvent) { reloadSoundsToolStripMenuItem.Enabled = _editor.Level.Settings.SoundsCatalogs.Count > 0; } // Update object bookmarks if (obj is Editor.BookmarkedObjectChanged) { var @event = (Editor.BookmarkedObjectChanged)obj; bookmarkRestoreObjectToolStripMenuItem.Enabled = @event.Current != null; } if (obj is Editor.LevelFileNameChangedEvent) { RefreshRecentProjectsList(); } // Quit editor if (obj is Editor.EditorQuitEvent) { Close(); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.IntersectClip(new RectangleF(new PointF(), ClientSize - new SizeF(_scrollSizeTotal, _scrollSizeTotal))); // Only proceed if texture is actually available if (VisibleTexture?.IsAvailable ?? false) { PointF drawStart = ToVisualCoord(new Vector2(0.0f, 0.0f)); PointF drawEnd = ToVisualCoord(new Vector2(VisibleTexture.Image.Width, VisibleTexture.Image.Height)); RectangleF drawArea = RectangleF.FromLTRB(drawStart.X, drawStart.Y, drawEnd.X, drawEnd.Y); // Draw background using (var textureBrush = new TextureBrush(Properties.Resources.misc_TransparentBackground)) e.Graphics.FillRectangle(textureBrush, drawArea); // Switch interpolation based on current view scale if (ViewScale >= 1.0) { e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor; } else { e.Graphics.InterpolationMode = InterpolationMode.Bicubic; } // Draw image VisibleTexture.Image.GetTempSystemDrawingBitmap(tempBitmap => { // System.Drawing being silly, it draws the first row of pixels only half, so everything would be shifted // To work around it, we have to do some silly coodinate changes :/ e.Graphics.DrawImage(tempBitmap, new RectangleF(drawArea.X, drawArea.Y, drawArea.Width + 0.5f * ViewScale, drawArea.Height + 0.5f * ViewScale), new RectangleF(-0.5f, -0.5f, tempBitmap.Width + 0.5f, tempBitmap.Height + 0.5f), GraphicsUnit.Pixel); }); OnPaintSelection(e); } else { string notifyMessage; if (string.IsNullOrEmpty(VisibleTexture?.Path)) { notifyMessage = "Click here to load new texture file."; } else { string fileName = PathC.GetFileNameWithoutExtensionTry(VisibleTexture?.Path) ?? ""; if (PathC.IsFileNotFoundException(VisibleTexture?.LoadException)) { notifyMessage = "Texture file '" + fileName + "' was not found!\n"; } else { notifyMessage = "Unable to load texture from file '" + fileName + "'.\n"; } notifyMessage += "Click here to choose a replacement.\n\n"; notifyMessage += "Path: " + (_editor.Level.Settings.MakeAbsolute(VisibleTexture?.Path) ?? ""); } RectangleF textArea = ClientRectangle; textArea.Size -= new SizeF(_scrollSizeTotal, _scrollSizeTotal); using (var b = new SolidBrush(Colors.DisabledText)) e.Graphics.DrawString(notifyMessage, Font, b, textArea, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); } // Draw borders using (Pen pen = new Pen(Colors.GreySelection, 1.0f)) e.Graphics.DrawRectangle(pen, new RectangleF(0, 0, ClientSize.Width - _scrollSizeTotal - 1, ClientSize.Height - _scrollSizeTotal - 1)); }
public static void Launch(LevelSettings settings, IWin32Window owner) { string executablePath = settings.MakeAbsolute(settings.GameExecutableFilePath); string levelPath = settings.MakeAbsolute(settings.GameLevelFilePath); // Try to launch the game try { var info = new ProcessStartInfo { WorkingDirectory = Path.GetDirectoryName(executablePath), FileName = executablePath }; // Start the game (i.e. "tomb4.exe") Process process = Process.Start(info); try { // Seperate thread to wait for the options dialog to appear // so it can be suppressed subsequently by sending WM_CLOSE. if (settings.GameVersion.Legacy() == TRVersion.Game.TR4 && settings.GameEnableQuickStartFeature && IsWindows) { Process process2 = process; Thread thread = new Thread(() => { try { Tomb4ConvinienceImprovements.Do(process2, info.WorkingDirectory, levelPath); } catch (Exception exc) { logger.Error(exc, "The 'Tomb4ConvinienceImprovements' thread caused issues."); } finally { process2?.Dispose(); } }); thread.IsBackground = true; thread.Priority = ThreadPriority.BelowNormal; thread.Start(); process = null; } } finally { process?.Dispose(); } } catch (Exception exc) { logger.Warn(exc, "Trying to launch the game '" + executablePath + "'."); // Show message string message = "\nGo to Tools -> Level Settings -> Game Paths to set a valid executable path."; if (PathC.IsFileNotFoundException(exc) || !File.Exists(executablePath)) { message = "Unable to find '" + executablePath + "'. " + message; } else { message = "Unable to start '" + executablePath + "' because a " + exc.GetType().Name + " occurred (" + exc.Message + "). " + message; } Editor.Instance.SendMessage(message, PopupType.Error); } }
private static bool LoadSamples(ChunkReader chunkIO, ChunkId idOuter, Wad2 wad, ref Dictionary <long, WadSample> outSamples, bool obsolete) { if (idOuter != Wad2Chunks.Samples) { return(false); } var samples = new Dictionary <long, WadSample>(); long obsoleteIndex = 0; // Move this into each chunk once we got rid of old style *.wad2 files. chunkIO.ReadChunks((id, chunkSize) => { if (id != Wad2Chunks.Sample) { return(false); } string FilenameObsolete = null; byte[] data = null; chunkIO.ReadChunks((id2, chunkSize2) => { if (id2 == Wad2Chunks.SampleIndex) { obsoleteIndex = chunkIO.ReadChunkLong(chunkSize2); } else if (id2 == Wad2Chunks.SampleFilenameObsolete) { FilenameObsolete = chunkIO.ReadChunkString(chunkSize2); } else if (id2 == Wad2Chunks.SampleData) { data = chunkIO.ReadChunkArrayOfBytes(chunkSize2); } else { return(false); } return(true); }); if (data == null && !string.IsNullOrEmpty(FilenameObsolete)) { string fullPath = Path.Combine(PathC.GetDirectoryNameTry(Assembly.GetEntryAssembly().Location), "Sounds\\TR4\\Samples", FilenameObsolete + ".wav"); data = File.ReadAllBytes(fullPath); } samples.Add(obsoleteIndex++, new WadSample("", WadSample.ConvertSampleFormat(data, sampleRate => obsolete ? new WadSample.ResampleInfo { Resample = false, SampleRate = WadSample.GameSupportedSampleRate } : new WadSample.ResampleInfo { Resample = true, SampleRate = sampleRate }))); return(true); }); outSamples = samples; return(true); }