prevent all empty filenames notice the error comment. private static async Task…
- User
prevent all empty filenames notice the error comment.
private static async Task MaterialsToFileAsync(Dictionary<string, OMATRuntime> materialList, string folder, string filename) { // Generate a unique filename if the provided filename is empty or null if (string.IsNullOrWhiteSpace(filename)) { filename = "materials_{DateTime.UtcNow:yyyyMMdd_HHmmss}_{Guid.NewGuid()}.mtl"; } else { filename = "{filename}.mtl"; }
codeusing (StreamWriter sw = new StreamWriter(Path.Combine(folder, filename))) { foreach (var kvp in materialList) { await sw.WriteLineAsync($"\nnewmtl {kvp.Key}\n"); await sw.WriteLineAsync("Ka 1.0 1.0 1.0\n"); await sw.WriteLineAsync("Kd 1.0 1.0 1.0\n"); await sw.WriteLineAsync("Ks 1.0 1.0 1.0\n"); await sw.WriteLineAsync("d 1.0\n"); await sw.WriteLineAsync("Ns 0.0\n"); await sw.WriteLineAsync("illum 2\n"); if (kvp.Value.textureName != null) { string destinationFile = kvp.Value.textureName; string relativeFile = Path.GetFileName(destinationFile); string fullDestinationPath = Path.Combine(folder, relativeFile); // Perform file copy on a separate thread. File.Copy(kvp.Value.textureName, fullDestinationPath); // ArgumentException: Empty file name is not legal. await sw.WriteLineAsync($"map_Kd {relativeFile}\n"); } await sw.WriteLineAsync(); } }}
- Assistant