Skip to content

Commit 89b5e38

Browse files
committed
fix: extract server files to temp directory before moving to final location
1 parent 550fd77 commit 89b5e38

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

MCPForUnity/Editor/Helpers/ServerInstaller.cs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -755,17 +755,34 @@ public static bool DownloadAndInstallServer()
755755
}
756756
}
757757

758-
// Ensure parent directory exists
759-
Directory.CreateDirectory(destRoot);
758+
// Extract to temp location first
759+
string tempExtractDir = Path.Combine(Path.GetTempPath(), $"mcp-server-extract-{Guid.NewGuid()}");
760+
Directory.CreateDirectory(tempExtractDir);
760761

761-
// Extract
762-
ZipFile.ExtractToDirectory(tempZip, destRoot);
762+
try
763+
{
764+
ZipFile.ExtractToDirectory(tempZip, tempExtractDir);
763765

764-
// Write version file
765-
File.WriteAllText(
766-
Path.Combine(destRoot, "src", VersionFileName),
767-
packageVersion
768-
);
766+
// The ZIP contains UnityMcpServer~ folder, find it and move its contents
767+
string extractedServerFolder = Path.Combine(tempExtractDir, "UnityMcpServer~");
768+
Directory.CreateDirectory(destRoot);
769+
CopyDirectoryRecursive(extractedServerFolder, destRoot);
770+
}
771+
finally
772+
{
773+
// Cleanup temp extraction directory
774+
try
775+
{
776+
if (Directory.Exists(tempExtractDir))
777+
{
778+
Directory.Delete(tempExtractDir, recursive: true);
779+
}
780+
}
781+
catch (Exception ex)
782+
{
783+
McpLog.Warn($"Could not fully delete temp extraction directory: {ex.Message}");
784+
}
785+
}
769786

770787
EditorUtility.ClearProgressBar();
771788
McpLog.Info($"Server v{packageVersion} downloaded and installed successfully!");
@@ -784,7 +801,11 @@ public static bool DownloadAndInstallServer()
784801
}
785802
finally
786803
{
787-
try { if (File.Exists(tempZip)) File.Delete(tempZip); } catch { }
804+
try {
805+
if (File.Exists(tempZip)) File.Delete(tempZip);
806+
} catch (Exception ex) {
807+
McpLog.Warn($"Could not delete temp zip file: {ex.Message}");
808+
}
788809
}
789810
}
790811

@@ -810,7 +831,10 @@ public static string GetInstalledServerVersion()
810831
return File.ReadAllText(versionPath)?.Trim() ?? string.Empty;
811832
}
812833
}
813-
catch { }
834+
catch (Exception ex)
835+
{
836+
McpLog.Warn($"Could not read version file: {ex.Message}");
837+
}
814838
return string.Empty;
815839
}
816840
}

0 commit comments

Comments
 (0)