/// <summary> /// Downloads windows version of a specific version of Blender (And extract it) /// </summary> /// <param name="version"></param> public void DownloadWindows(BlenderVersion version) { string os = "windows64"; string ext = "zip"; string archiveName = $"{version.Name}-{os}.{ext}"; string archivePath = Path.Combine(GetBlenderDataPath(), archiveName); try { Directory.CreateDirectory(GetBlenderDataPath()); using (WebClient client = new WebClient()) { Console.WriteLine($"Downloading {version.Name}..."); client.DownloadFile(version.UrlWindows64, archivePath); } Console.WriteLine($"Extracting {version.Name}..."); ZipFile.ExtractToDirectory(archivePath, GetBlenderDataPath()); Console.WriteLine($"{version.Name} ready"); } catch (Exception ex) { if (Directory.Exists(GetVersionPath(version.Name, os))) { Directory.Delete(GetVersionPath(version.Name, os)); } if (File.Exists(archivePath)) { File.Delete(archivePath); } } }
/// <summary> /// Downloads a linux version of a specific version of Blender (And extract it) /// </summary> /// <param name="version"></param> public void DownloadLinux(BlenderVersion version) { string os = "linux64"; string ext = "tar.xz"; string archiveName = $"{version.Name}-{os}.{ext}"; string archivePath = Path.Combine(GetBlenderDataPath(), archiveName); try { Directory.CreateDirectory(GetBlenderDataPath()); using (WebClient client = new WebClient()) { Console.WriteLine($"Downloading {version.Name}..."); client.DownloadFile(version.UrlLinux64, archivePath); } Console.WriteLine($"Extracting {version.Name}..."); using (FileStream str = new FileStream(archivePath, FileMode.Open)) using (var reader = ReaderFactory.Open(str)) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { reader.WriteEntryToDirectory(GetBlenderDataPath(), new SharpCompress.Common.ExtractionOptions() { ExtractFullPath = true, Overwrite = true }); } } } EnsureOldDirectoryFormat(version.Name, os); Console.WriteLine($"{version.Name} ready"); Console.WriteLine("Calling chmod for required permissions"); //Otherwise can't run blender, not particularily happy with this. new ProcessStartInfo() { FileName = "chmod", Arguments = "-R u=rwx " + GetVersionPath(version.Name, os), UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true }.WaitAndPrint(); } catch (Exception ex) { if (Directory.Exists(GetVersionPath(version.Name, os))) { Directory.Delete(GetVersionPath(version.Name, os)); } if (File.Exists(archivePath)) { File.Delete(archivePath); } } }
public async void ShowInterfaceInstall() { HideInterfaces(); if (VersionName == null) { await MessageWindow.Show(this, "Name missing", "No version name was provided"); ShowInterfaceName(); } else { List <BlenderVersion> existing = BlenderVersion.GetBlenderVersions(SystemInfo.RelativeToApplicationDirectory("VersionCache"), SystemInfo.RelativeToApplicationDirectory("VersionCustom")); if (existing.Any(x => x.Name.ToLower() == VersionName.ToLower())) { await MessageWindow.Show(this, "Name already exists", "This version name already exists"); ShowInterfaceName(); } else { string path = BlenderManager.GetVersionPath(SystemInfo.RelativeToApplicationDirectory(ServerSettings.Instance.BlenderData), VersionName, SystemInfo.GetOSName()); _outputPath.Text = Path.GetFullPath(path); _interfaceInstall.IsVisible = true; } } }
public void GetBlenderVersions() { List <BlenderVersion> versions = BlenderVersion.GetBlenderVersions(); Assert.IsTrue(versions.Count > 10); Assert.IsFalse(existing_versions.Any(x => !versions.Any(y => y.Name == x))); Console.WriteLine(string.Join('\n', versions.Select(x => x.Name))); }
private void EnsureOldDirectoryFormat(string version, string os) { string expectedOld = GetVersionPath(version, BlenderVersion.GetOldOSName(os)); string expectedNew = GetVersionPath(version, BlenderVersion.GetNewOSName(os)); //For newer builds, return to old format if (Directory.Exists(expectedNew) && !Directory.Exists(expectedOld)) { Directory.Move(expectedNew, expectedOld); } }
private void StartVersion(BlenderVersion Version) { string args = ""; if ((bool)CheckboxConsole.IsChecked) { args += " -con"; } if ((bool)CheckboxAutoExec.IsChecked) { args += " -y"; } if ((bool)CheckboxBorder.IsChecked) { args += " -w"; } if ((bool)CheckboxFullscreen.IsChecked) { args += " -W"; } if ((bool)CheckboxDefault.IsChecked) { args += " --factory-startup"; } if ((bool)CheckboxRegister.IsChecked) { args += " -r"; } var p = new Process() { StartInfo = new ProcessStartInfo { FileName = $"{Version.Path}", Arguments = args, RedirectStandardError = false, RedirectStandardOutput = false } }; p.Start(); if ((bool)CheckboxRegister.IsChecked) { p.WaitForExit(1000); CheckboxRegister.IsChecked = false; StartVersion(Version); } }
/// <summary> /// Download a specific version of Blender for OS /// </summary> public void Download(string os, BlenderVersion version) { switch (os) { case "windows64": DownloadWindows(version); break; case "linux64": DownloadLinux(version); break; case "macOS": DownloadMacOS(version); break; default: throw new NotImplementedException("Unknown OS"); } }
public async void ShowInterfaceComplete() { HideInterfaces(); string blenderData = SystemInfo.RelativeToApplicationDirectory("BlenderData"); string executable = BlenderManager.GetVersionExecutablePath(blenderData, VersionName); if (!BlenderManager.IsVersionValid(blenderData, VersionName)) { await MessageWindow.Show(this, "Missing Installation", $"Expecting Blender executable on path\n{executable}"); ShowInterfaceInstall(); } else { List <string> lines = BlenderVersion.GetCustomBlenderVersions(SystemInfo.RelativeToApplicationDirectory("VersionCustom")).Select(x => x.Name).ToList(); lines.Add(VersionName); File.WriteAllLines(SystemInfo.RelativeToApplicationDirectory("VersionCustom"), lines.ToArray()); _interfaceComplete.IsVisible = true; } }
/// <summary> /// Prepare a version of Blender /// </summary> /// <param name="version"></param> public void Prepare(string version) { BlenderVersion v = BlenderVersion.FindVersion(version, SystemInfo.RelativeToApplicationDirectory("VersionCache"), SystemInfo.RelativeToApplicationDirectory("VersionCustom")); if (v == null) { throw new ArgumentException("Version not found"); } string targetDir = GetVersionPath(version, SystemInfo.GetOSName()); if (Directory.Exists(targetDir)) { Console.WriteLine($"{version} already present"); } else if (v.IsCustom) { throw new ArgumentException("Custom version missing"); } else { Download(SystemInfo.GetOSName(), v); } }
/// <summary> /// Downloads macos version of a specific version of Blender (And extract it) /// </summary> /// <param name="version"></param> public void DownloadMacOS(BlenderVersion version) { string os = "macOS"; string ext = "dmg"; string archiveName = $"{version.Name}-{os}.{ext}"; string archivePath = Path.Combine(GetBlenderDataPath(), archiveName); try { Directory.CreateDirectory(GetBlenderDataPath()); using (WebClient client = new WebClient()) { Console.WriteLine($"Downloading {version.Name}..."); client.DownloadFile(version.UrlMacOS, archivePath); } Console.WriteLine($"Extracting {version.Name}..."); string versionPath = GetVersionPath(version.Name, os); string imagePath = versionPath + "-image"; Directory.CreateDirectory(imagePath); Console.WriteLine($"Mounting [{archivePath}] to [{imagePath}]"); Process mountProcess = new Process() { StartInfo = new ProcessStartInfo() { FileName = "hdiutil", Arguments = $"attach -mountpoint \"{imagePath}\" \"{archivePath}\"", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true } }; mountProcess.Start(); mountProcess.WaitForExit(); Console.WriteLine("Mounted"); Directory.CreateDirectory(versionPath); Console.WriteLine("Copying Blender Files"); CopyRecursive(Path.Combine(imagePath, "Blender.app"), versionPath); Console.WriteLine("Unmounting"); Process unmountProcess = new Process() { StartInfo = new ProcessStartInfo() { FileName = "hdiutil", Arguments = $"detach \"{imagePath}\"", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true } }; unmountProcess.Start(); unmountProcess.WaitForExit(); Console.WriteLine("Unmounted"); Console.WriteLine($"{version.Name} ready"); } catch (Exception ex) { if (Directory.Exists(GetVersionPath(version.Name, os))) { Directory.Delete(GetVersionPath(version.Name, os)); } if (File.Exists(archivePath)) { File.Delete(archivePath); } } }