Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Aetopia committed Jun 24, 2024
0 parents commit 1aad802
Show file tree
Hide file tree
Showing 11 changed files with 1,103 additions and 0 deletions.
484 changes: 484 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Aetopia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
91 changes: 91 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Smoothie Installer
An all in one installer for Smoothie.

## Features
- Download & install the latest version of Smoothie.

- Install FFmpeg if required.

- Repair your current Smoothie installation if required.

- You may use this option to update Smoothie also.

- Clean uninstallation, no files are left behind.

## Usage
- Download the latest version from [GitHub Releases](https://github.com/Aetopia/SmoothieInstaller/releases/latest).
- Run `SmoothieInstaller.exe`.

> [!TIP]
> Smoothie Installer is intended for those who aren't familiar with package managers.<br>
> If possible, try to transition to [Scoop](https://scoop.sh) for Smoothie.<br>
> Package managers provide a clean way to install, update and uninstall apps.<br><br>
> If you want to transition, do the following:
> - If you have used Smoothie Installer, do the following:
> - Backup any configuration files, if desired.
> - Uninstall Smoothie.
>
> - Run the following commands in PowerShell:
> ```powershell
> irm "get.scoop.sh" | iex
> scoop install git ffmpeg
> scoop bucket add utils "https://github.com/couleur-tweak-tips/utils"
> scoop install smoothie
> ```
> - You may update FFmpeg and Smoothie using the following command:
> ```powershell
> scoop update ffmpeg smoothie
> ```
## FAQ
- How can I update Smoothie using Smoothie Installer?<br>
- You can update Smoothie by repairing your current Smoothie installation by re-running `SmoothieInstaller.exe`.
- You can update Smoothie by modifying/changing the installation:
- Control Panel
- Go to Programs → Programs & Features.
- Select Smoothie.
- Select <kbd>Change</kbd>.
- Repair the installation.
- Windows Settings
- Go to Apps → Apps & features.
- Select Smoothie.
- Select <kbd>Modify</kbd>.
- Repair the installation.
- How can I use Smoothie?
- Please check out [Smoothie's documentation](https://ctt.cx/video/smoothie/).
- How can I uninstall Smoothie using Smoothie Installer?
- You may uninstall Smoothie via the Control Panel or Windows Settings.
- How can I remove Smoothie Installer's FFmpeg installation?
- Do the following:
- Go the following directory, `%LOCALAPPDATA%\Programs\Smoothie\bin`.
- Delete the following:
- `ffmpeg.exe`
- `ffprobe.exe`
- `ffplay.exe`
- Where does Smoothie Installer install Smoothie?
- Smoothie Installer installs Smoothie to `%LOCALAPPDATA%\Programs\Smoothie`.
## Building
1. Download the following:
- [.NET SDK](https://dotnet.microsoft.com/en-us/download)
- [.NET Framework 4.8.1 Developer Pack](https://dotnet.microsoft.com/en-us/download/dotnet-framework/thank-you/net481-developer-pack-offline-installer)
2. Run the following command to compile:
```cmd
dotnet publish "src/SmoothieInstaller.csproj"
```
14 changes: 14 additions & 0 deletions src/.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>

<asmv3:application>
<asmv3:windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
38 changes: 38 additions & 0 deletions src/FFmpeg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.IO;
using System.Threading;
using System.IO.Compression;
using System.Collections.Generic;

static class FFmpeg
{
internal const string Address = "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl-shared.zip";

static readonly IEnumerable<string> paths = ["ffmpeg.exe", "ffprobe.exe", "ffplay.exe"];

static CancellationTokenSource source = null;

internal static bool Check()
{
foreach (var path in paths) if (!NativeMethods.PathFindOnPath(new(path, 260))) return false;
return true;
}

internal static void Cancel() { source?.Cancel(); while (source != null) ; }

internal static void Extract(string archiveFileName)
{
source = new();

using ZipArchive zip = ZipFile.OpenRead(archiveFileName);
foreach (var entry in zip.Entries)
{
if (source.IsCancellationRequested) return;
if (entry.Name.EndsWith(".exe") || entry.Name.EndsWith(".dll") || entry.Name.Equals("LICENSE.txt"))
entry.ExtractToFile(Path.Combine(Installer.BinariesPath, entry.Name), true);
}

NativeMethods.DeleteFile(archiveFileName);
source.Dispose();
source = null;
}
}
129 changes: 129 additions & 0 deletions src/Installer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Linq;
using System.Xml;
using Microsoft.Win32;
using System.Threading;
using System.Reflection;
using System.IO.Compression;
using System.Management.Automation;
using System.Runtime.Serialization.Json;

static class Installer
{
static readonly WebClient client = new();

static CancellationTokenSource source = null;

internal readonly static string InstallationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs", "Smoothie");

internal readonly static string BinariesPath = Path.Combine(InstallationPath, "bin");

internal static bool Check()
{
StringBuilder path = new("smoothie-rs.exe", 260);
return NativeMethods.PathFindOnPath(path) && Path.GetDirectoryName(path.ToString()).Equals(BinariesPath, StringComparison.OrdinalIgnoreCase);
}

internal static void Cancel() { source?.Cancel(); while (source != null) ; }

internal static string Start()
{
Directory.CreateDirectory(InstallationPath);
var value = Environment.GetEnvironmentVariable("Path");
if (!value.Contains(BinariesPath))
Environment.SetEnvironmentVariable("Path", $"{BinariesPath};{value.Trim(';')}", EnvironmentVariableTarget.User);

client.Headers["User-Agent"] = "Smoothie Installer";
using var reader = JsonReaderWriterFactory.CreateJsonReader(
Encoding.UTF8.GetBytes(client.DownloadString("https://api.github.com/repos/couleur-tweak-tips/smoothie-rs/releases/latest")),
XmlDictionaryReaderQuotas.Max);
XmlDocument xml = new();
xml.Load(reader);

return xml.GetElementsByTagName("browser_download_url")[0].InnerText;
}

internal static void Extract(string archiveFileName)
{
source = new();

using ZipArchive zip = ZipFile.OpenRead(archiveFileName);
foreach (var entry in zip.Entries)
{
if (source.IsCancellationRequested) return;
if (entry.FullName.Equals("smoothie-rs/") || entry.Name.Equals("makeShortcuts.cmd")) continue;
string path = Path.Combine(InstallationPath, entry.FullName.Split(new string[] { "smoothie-rs/" }, StringSplitOptions.RemoveEmptyEntries)[0]);

if (entry.Name.Equals("recipe.ini") && File.Exists(path)) continue;
if (entry.FullName.Last().Equals(Path.AltDirectorySeparatorChar))
Directory.CreateDirectory(path);
else entry.ExtractToFile(path, true);
}

NativeMethods.DeleteFile(archiveFileName);
source.Dispose();
source = null;
}

internal static void CreateEntry()
{
var path = Path.Combine(BinariesPath, "SmoothieInstaller.exe");
try { Directory.CreateDirectory(BinariesPath); }
catch (IOException) { };
NativeMethods.CopyFile(Assembly.GetExecutingAssembly().Location, path);

PowerShell.Create().AddScript($"""
$TargetPath = "{InstallationPath}"
$Path = [System.Environment]::GetFolderPath("Programs")
New-Item -ItemType "Directory" -Path $Path
$Path = "$Path\Smoothie"
New-Item -ItemType "Directory" -Path $Path
$WshShell = New-Object -ComObject "WScript.Shell"
$Shortcut = $WshShell.CreateShortcut("$Path\Smoothie.lnk")
$Shortcut.TargetPath = "$TargetPath\launch.cmd"
$Shortcut.IconLocation = "$TargetPath\bin\smoothie-rs.exe"
$Shortcut.Description = "Smoothen up your gameplay footage with Smoothie, yum!"
$Shortcut.Save()
$Shortcut = $WshShell.CreateShortcut("$Path\Smoothie Recipe.lnk")
$Shortcut.TargetPath = "$TargetPath\recipe.ini"
$Shortcut.Save()
$Shortcut = $WshShell.CreateShortcut("$([System.Environment]::GetFolderPath("SendTo"))\Smoothie.lnk")
$Shortcut.TargetPath = "$TargetPath\bin\smoothie-rs.exe"
$Shortcut.Arguments = "--tui -i";
$Shortcut.Save()
""").Invoke();

Registry.CurrentUser.DeleteSubKeyTree(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Smoothie", false);
using RegistryKey registryKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Smoothie", true);
registryKey.SetValue("DisplayIcon", Path.Combine(BinariesPath, "smoothie-rs.exe"));
registryKey.SetValue("DisplayName", "Smoothie");
registryKey.SetValue("Publisher", "Couleur Tweak Tips");
registryKey.SetValue("ModifyPath", path);
var temp = Path.GetTempPath();
registryKey.SetValue("UninstallString", @$"cmd.exe /c ""copy /Y ""{path}"" ""{temp}\SmoothieInstaller.exe"" && start """" ""{temp}\SmoothieInstaller.exe"" /Uninstall""");
}

internal static void Uninstall()
{
try { Directory.Delete(InstallationPath, true); }
catch (DirectoryNotFoundException) { }

try { Directory.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "Smoothie"), true); }
catch (DirectoryNotFoundException) { }

NativeMethods.DeleteFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SendTo), "Smoothie.lnk"));
Registry.CurrentUser.DeleteSubKeyTree(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Smoothie", false);

var value = Environment.GetEnvironmentVariable("Path").Replace(BinariesPath, string.Empty).Trim(';');
Environment.SetEnvironmentVariable("Path", value, EnvironmentVariableTarget.User);
}
}
Loading

0 comments on commit 1aad802

Please sign in to comment.