45 lines
2.6 KiB
C#
45 lines
2.6 KiB
C#
using Microsoft.Win32;
|
|
using Launcher.Next.Core;
|
|
namespace Launcher.Next.Autodesk;
|
|
public interface IRegistryReader { object? GetValue(string path, string name); }
|
|
public sealed class WindowsRegistryReader : IRegistryReader { public object? GetValue(string path, string name) => Registry.LocalMachine.OpenSubKey(path)?.GetValue(name); }
|
|
public sealed class PlantProductDiscovery(IRegistryReader registry) : IProductDiscovery
|
|
{
|
|
public ProductInstallation? DiscoverPlant3D(int year)
|
|
{
|
|
var install = registry.GetValue($@"SOFTWARE\Autodesk\AutoCAD\R25.1\ACAD-xxxx:409", "InstallDir") as string;
|
|
if (string.IsNullOrWhiteSpace(install)) return null; var exe = Path.Combine(install, "acad.exe");
|
|
return File.Exists(exe) ? new(exe, year.ToString(), "x64", []) : null;
|
|
}
|
|
}
|
|
public sealed class StartupScriptBuilder : IStartupScriptBuilder
|
|
{
|
|
public string BuildNetloadScript(string root, string entry)
|
|
{ var full = Path.GetFullPath(Path.Combine(root, entry)); if (!full.StartsWith(Path.GetFullPath(root) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase) || !File.Exists(full)) throw new InvalidOperationException("UNTRUSTED_ENTRY_PATH"); return $"_.NETLOAD\n\"{full.Replace("\"", "\\\"")}\"\n"; }
|
|
public string BuildAutomationScript(string root, string entry, string fixtureOrthoDwg)
|
|
{
|
|
var fixture = Path.GetFullPath(fixtureOrthoDwg);
|
|
if (!File.Exists(fixture)) throw new InvalidOperationException("AUTOMATION_FIXTURE_NOT_FOUND");
|
|
var quote = (string value) => "\"" + value.Replace("\"", "\\\"") + "\"";
|
|
return "_.OPEN\n" + quote(fixture) + "\n" + BuildNetloadScript(root, entry) +
|
|
"PHP_REC_AUTOMATION_PREPARE\nPXP-OA\nPXP-OA\nPHP_REC_AUTOMATION_FINALIZE\n";
|
|
}
|
|
}
|
|
public sealed class DryRunAutodeskProcessLauncher : IAutodeskProcessLauncher
|
|
{
|
|
public PreparedLaunch Prepare(LaunchRequest r)
|
|
{
|
|
if (!r.DryRun) throw new InvalidOperationException("PROCESS_START_DISABLED_IN_FOUNDATION");
|
|
var startInfo = new System.Diagnostics.ProcessStartInfo
|
|
{
|
|
FileName = r.Product.ExecutablePath,
|
|
WorkingDirectory = Path.GetDirectoryName(r.Product.ExecutablePath)!,
|
|
UseShellExecute = false
|
|
};
|
|
startInfo.ArgumentList.Add("/product"); startInfo.ArgumentList.Add("PLNT3D");
|
|
startInfo.ArgumentList.Add("/p"); startInfo.ArgumentList.Add(r.Profile);
|
|
startInfo.ArgumentList.Add("/b"); startInfo.ArgumentList.Add(r.StartupScriptPath);
|
|
return new(startInfo.FileName, startInfo.ArgumentList.ToArray(), startInfo.WorkingDirectory, false);
|
|
}
|
|
}
|