72 lines
2.6 KiB
C#
72 lines
2.6 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
|
|
public class ReadmeUpdater : EditorWindow
|
|
{
|
|
private const string PythonScriptPath = "BABA_YAGA_Updater/main.py";
|
|
private const string VenvPythonPath = "BABA_YAGA_Updater/.venv/Scripts/python.exe";
|
|
private const string UpdaterDir = "BABA_YAGA_Updater";
|
|
|
|
[MenuItem("BABA YAGA/Update README")]
|
|
public static void UpdateReadme()
|
|
{
|
|
string projectRoot = Directory.GetParent(Application.dataPath).FullName;
|
|
string fullVenvPath = Path.Combine(projectRoot, VenvPythonPath);
|
|
string fullScriptPath = Path.Combine(projectRoot, PythonScriptPath);
|
|
string workingDir = Path.Combine(projectRoot, UpdaterDir);
|
|
|
|
if (!File.Exists(fullVenvPath))
|
|
{
|
|
UnityEngine.Debug.LogError($"[README Updater] Python venv not found at: {fullVenvPath}. Please ensure the .venv is set up in BABA_YAGA_Updater.");
|
|
return;
|
|
}
|
|
|
|
UnityEngine.Debug.Log("[README Updater] Starting update process...");
|
|
|
|
ProcessStartInfo startInfo = new ProcessStartInfo
|
|
{
|
|
FileName = fullVenvPath,
|
|
Arguments = $"\"{fullScriptPath}\"",
|
|
WorkingDirectory = workingDir,
|
|
UseShellExecute = false,
|
|
RedirectStandardOutput = true,
|
|
RedirectStandardError = true,
|
|
StandardOutputEncoding = System.Text.Encoding.UTF8,
|
|
StandardErrorEncoding = System.Text.Encoding.UTF8,
|
|
CreateNoWindow = true
|
|
};
|
|
|
|
// Force Python to use UTF-8 for IO to handle emojis
|
|
startInfo.EnvironmentVariables["PYTHONIOENCODING"] = "utf-8";
|
|
|
|
using (Process process = Process.Start(startInfo))
|
|
{
|
|
using (StreamReader reader = process.StandardOutput)
|
|
{
|
|
string result = reader.ReadToEnd();
|
|
if (!string.IsNullOrEmpty(result))
|
|
UnityEngine.Debug.Log($"[README Updater] Output:\n{result}");
|
|
}
|
|
|
|
using (StreamReader reader = process.StandardError)
|
|
{
|
|
string errors = reader.ReadToEnd();
|
|
if (!string.IsNullOrEmpty(errors))
|
|
UnityEngine.Debug.LogError($"[README Updater] Errors:\n{errors}");
|
|
}
|
|
|
|
process.WaitForExit();
|
|
if (process.ExitCode == 0)
|
|
{
|
|
UnityEngine.Debug.Log("🎉 [README Updater] README.md successfully updated!");
|
|
}
|
|
else
|
|
{
|
|
UnityEngine.Debug.LogError($"[README Updater] Process exited with code {process.ExitCode}");
|
|
}
|
|
}
|
|
}
|
|
}
|