private static void CreateFile(string fullPath, CodeCompileUnit compileUnit) { // Generate the code with the C# code provider. CSharpCodeProvider provider = new CSharpCodeProvider(); // Build the output file name. string fullSourceFilePath = fullPath; //Debug.Log("[SteamVR] Writing class to: " + fullSourceFilePath); string path = GetClassPath(); string[] parts = path.Split('/'); for (int partIndex = 0; partIndex < parts.Length - 1; partIndex++) { string directoryPath = string.Join("/", parts.Take(partIndex + 1).ToArray()); if (Directory.Exists(directoryPath) == false) { Directory.CreateDirectory(directoryPath); //Debug.Log("[SteamVR] Created directory: " + directoryPath); } } string priorMD5 = null; FileInfo file = new FileInfo(fullSourceFilePath); if (file.Exists) { file.IsReadOnly = false; priorMD5 = SteamVR_Utils.GetBadMD5HashFromFile(fullSourceFilePath); } // Create a TextWriter to a StreamWriter to the output file. using (StreamWriter sw = new StreamWriter(fullSourceFilePath, false)) { IndentedTextWriter tw = new IndentedTextWriter(sw, " "); // Generate source code using the code provider. provider.GenerateCodeFromCompileUnit(compileUnit, tw, new CodeGeneratorOptions() { BracingStyle = "C" }); // Close the output file. tw.Close(); string newMD5 = SteamVR_Utils.GetBadMD5HashFromFile(fullSourceFilePath); if (priorMD5 != newMD5) { fileChanged = true; } } //Debug.Log("[SteamVR] Complete! Input class at: " + fullSourceFilePath); }
private static void CreateFile(string fullPath, CodeCompileUnit compileUnit) { // Generate the code with the C# code provider. CSharpCodeProvider provider = new CSharpCodeProvider(); // Build the output file name. string fullSourceFilePath = fullPath; //Debug.Log("[SteamVR] Writing class to: " + fullSourceFilePath); string path = GetClassPath(); string priorMD5 = null; FileInfo file = new FileInfo(fullSourceFilePath); if (file.Exists) { file.IsReadOnly = false; priorMD5 = SteamVR_Utils.GetBadMD5HashFromFile(fullSourceFilePath); } // Create a TextWriter to a StreamWriter to the output file. using (StreamWriter sw = new StreamWriter(fullSourceFilePath, false)) { IndentedTextWriter tw = new IndentedTextWriter(sw, " "); // Generate source code using the code provider. provider.GenerateCodeFromCompileUnit(compileUnit, tw, new CodeGeneratorOptions() { BracingStyle = "C" }); // Close the output file. tw.Close(); string newMD5 = SteamVR_Utils.GetBadMD5HashFromFile(fullSourceFilePath); if (priorMD5 != newMD5) { fileChanged = true; } } //Debug.Log("[SteamVR] Complete! Input class at: " + fullSourceFilePath); }