1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.IO.Compression;
- using Cysharp.Threading.Tasks;
- using KYFramework;
- namespace VRPlatform
- {
- public static class VRResourceEntitySystem
- {
- public static void Run(this VRResourceEntity self)
- {
- self.Process = new Process()
- {
- StartInfo = new ProcessStartInfo()
- {
- FileName = self.Exe,
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- UseShellExecute = false,
- CreateNoWindow = true,
- WindowStyle = ProcessWindowStyle.Normal
- }
- };
-
- self.Process.Start();
-
- // Run resource
- Log.Info($"Run resource [{self.VRResourceId}]");
- }
-
- public static void Stop(this VRResourceEntity self)
- {
- self.Process?.Kill();
- self.Process = null;
- // Stop resource
- Log.Info($"Stop resource [{self.VRResourceId}]");
- }
-
- public static async UniTask Download(this VRResourceEntity self, Action<double> progressCallback = null)
- {
- // Download resource
- Downloader downloader = new Downloader();
- await downloader.DownloadFileAsync(self.Url, self.FilePath,progressCallback);
- // 解压缩 self.FilePath
- string extractPath = Path.Combine(Path.GetDirectoryName(self.FilePath), Path.GetFileNameWithoutExtension(self.FilePath));
- ZipFile.ExtractToDirectory(self.FilePath, extractPath);
- File.Delete(self.FilePath);
- Log.Info($"Download resource [{self.VRResourceId}]");
- }
- }
- }
|