示例代码:
public static async Task UnzipPythonToLocalFolderAsync()
{
var localFolder = ApplicationData.Current.LocalFolder;
var pythonLocalPath = Path.Combine(localFolder.Path, "python");
// 检查是否已解压过
if (Directory.Exists(pythonLocalPath) && Directory.GetFiles(pythonLocalPath).Length > 0)
return;
// 获取包内 python.zip 的物理路径
var installFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var pythonZipFile = await installFolder.GetFileAsync("python.zip");
var pythonZipPath = pythonZipFile.Path;
// 解压到 LocalFolder/python
ZipFile.ExtractToDirectory(pythonZipPath, pythonLocalPath, overwriteFiles: true);
}