Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions .github/workflows/RocketModFix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ jobs:
nuget_push: false
github_token: ${{ secrets.PAT }}

- name: Install zip
run: sudo apt-get install zip

- name: Zip Rocket.AutoInstaller artifacts
run: "cd ./Rocket.AutoInstaller/bin/Release/net461/linux-x64/Rocket.AutoInstaller && zip -qq -r ./Rocket.AutoInstaller.zip *"

- name: Build Rocket.Unturned.Module
uses: ./.github/actions/project-build
id: unturned-module-build
Expand All @@ -77,23 +71,26 @@ jobs:
nuget_push: false
github_token: ${{ secrets.PAT }}

- name: Zip Rocket.Unturned artifacts
run: "cd ./Rocket.Unturned/bin/Release/net461/linux-x64/Rocket.Unturned && zip -qq -r ./Rocket.Unturned.Module.zip *"

- name: Upload Rocket.AutoInstaller
uses: actions/upload-artifact@v4
with:
name: Rocket.AutoInstaller.zip
path: "./Rocket.AutoInstaller/bin/Release/net461/linux-x64/Rocket.AutoInstaller/Rocket.AutoInstaller.zip"
name: Rocket.AutoInstaller
path: "./Rocket.AutoInstaller/bin/Release/net461/linux-x64/Rocket.AutoInstaller/"
if-no-files-found: error

- name: Upload Rocket.Unturned.Module
uses: actions/upload-artifact@v4
with:
name: Rocket.Unturned.Module.zip
path: "./Rocket.Unturned/bin/Release/net461/linux-x64/Rocket.Unturned/Rocket.Unturned.Module.zip"
name: Rocket.Unturned.Module
path: "./Rocket.Unturned/bin/Release/net461/linux-x64/Rocket.Unturned/"
if-no-files-found: error

- name: Zip Rocket.AutoInstaller artifacts
run: "cd ./Rocket.AutoInstaller/bin/Release/net461/linux-x64/Rocket.AutoInstaller && zip -qq -r ./Rocket.AutoInstaller.zip *"

- name: Zip Rocket.Unturned artifacts
run: "cd ./Rocket.Unturned/bin/Release/net461/linux-x64/Rocket.Unturned && zip -qq -r ./Rocket.Unturned.Module.zip *"

- name: Create Release
if: github.event_name == 'create' && github.event.ref_type == 'tag'
uses: ncipollo/release-action@v1.20.0
Expand Down
89 changes: 89 additions & 0 deletions Rocket.AutoInstaller/Installation/ExtrasInstaller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using System.Collections;
using System.IO;
using System.IO.Compression;
using System.Linq;
using SDG.Unturned;
using UnityEngine.Networking;

namespace Rocket.AutoInstaller.Installation
{
public static class ExtrasInstaller
{
public static IEnumerator InstallRocketFromExtras()
{
CommandWindow.Log("Installing from Extras...");

var extrasPath = Path.Combine(ReadWrite.PATH, "Extras");
if (!Directory.Exists(extrasPath))
{
CommandWindow.LogError("Extras directory not found");
yield break;
}

var moduleZipPath = Path.Combine(extrasPath, "Rocket.Unturned.Module.zip");
if (!File.Exists(moduleZipPath))
{
CommandWindow.LogError("Rocket.Unturned.Module.zip not found in Extras");
yield break;
}

CommandWindow.Log($"Found module: {moduleZipPath}");

var modulesPath = Path.Combine(ReadWrite.PATH, "Modules");
var targetPath = Path.Combine(modulesPath, "Rocket.Unturned.Module.zip");

try
{
File.Copy(moduleZipPath, targetPath, true);
CommandWindow.Log("Copied module to Modules directory");
}
catch (Exception ex)
{
CommandWindow.LogError($"Failed to copy module: {ex}");
yield break;
}

ExtractModule(targetPath, modulesPath);
}

private static void ExtractModule(string zipPath, string extractPath)
{
try
{
using var archive = ZipFile.OpenRead(zipPath);
var extractDir = Path.Combine(extractPath, "Rocket.Unturned");

if (Directory.Exists(extractDir))
{
Directory.Delete(extractDir, true);
}
Directory.CreateDirectory(extractDir);
foreach (var entry in archive.Entries)
{
if (string.IsNullOrEmpty(entry.Name))
continue;

var entryPath = Path.Combine(extractDir, entry.FullName);
var entryDir = Path.GetDirectoryName(entryPath);

if (!string.IsNullOrEmpty(entryDir) && !Directory.Exists(entryDir))
{
Directory.CreateDirectory(entryDir);
}

if (!string.IsNullOrEmpty(entry.Name))
{
entry.ExtractToFile(entryPath, true);
}
}

File.Delete(zipPath);
}
catch (Exception ex)
{
CommandWindow.LogError($"Failed to extract: {ex}");
}
}
}
}
46 changes: 46 additions & 0 deletions Rocket.AutoInstaller/Installation/GenericUriDownloader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections;
using System.IO;
using SDG.Unturned;
using UnityEngine.Networking;

namespace Rocket.AutoInstaller.Installation
{
public static class GenericUriDownloader
{
public static bool IsUri(string path)
{
if (string.IsNullOrWhiteSpace(path))
return false;

return Uri.TryCreate(path, UriKind.Absolute, out _);
}

public static IEnumerator DownloadFromUri(string uri, Action<byte[]> onSuccess, Action<string> onError)
{
if (!IsUri(uri))
{
onError?.Invoke("Invalid URI format.");
yield break;
}

CommandWindow.Log($"Downloading: {uri}");

var request = UnityWebRequest.Get(uri);
request.SetRequestHeader("User-Agent", "RocketModFix");
request.redirectLimit = 5;

yield return request.SendWebRequest();

if (request.result != UnityWebRequest.Result.Success)
{
onError?.Invoke($"Failed to download from URI: {request.error} (Status: {request.responseCode})");
yield break;
}

var data = request.downloadHandler.data;

onSuccess?.Invoke(data);
}
}
}
28 changes: 28 additions & 0 deletions Rocket.AutoInstaller/Installation/GitHubAsset.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Newtonsoft.Json;

namespace Rocket.AutoInstaller.Installation
Expand All @@ -5,18 +6,45 @@
public class GitHubAsset
{
[JsonProperty("url")]
public string Url { get; set; }

Check warning on line 9 in Rocket.AutoInstaller/Installation/GitHubAsset.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("name")]
public string Name { get; set; }

Check warning on line 12 in Rocket.AutoInstaller/Installation/GitHubAsset.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("content_type")]
public string ContentType { get; set; }

Check warning on line 15 in Rocket.AutoInstaller/Installation/GitHubAsset.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'ContentType' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("size")]
public int Size { get; set; }

[JsonProperty("browser_download_url")]
public string BrowserDownloadUrl { get; set; }

Check warning on line 21 in Rocket.AutoInstaller/Installation/GitHubAsset.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'BrowserDownloadUrl' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

public class GitHubRelease
{
[JsonProperty("url")]
public string Url { get; set; }

Check warning on line 27 in Rocket.AutoInstaller/Installation/GitHubAsset.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("tag_name")]
public string TagName { get; set; }

Check warning on line 30 in Rocket.AutoInstaller/Installation/GitHubAsset.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'TagName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("name")]
public string Name { get; set; }

Check warning on line 33 in Rocket.AutoInstaller/Installation/GitHubAsset.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("body")]
public string Body { get; set; }

Check warning on line 36 in Rocket.AutoInstaller/Installation/GitHubAsset.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'Body' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("draft")]
public bool Draft { get; set; }

[JsonProperty("prerelease")]
public bool Prerelease { get; set; }

[JsonProperty("published_at")]
public DateTime PublishedAt { get; set; }

[JsonProperty("assets")]
public GitHubAsset[] Assets { get; set; }

Check warning on line 48 in Rocket.AutoInstaller/Installation/GitHubAsset.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'Assets' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
}
32 changes: 0 additions & 32 deletions Rocket.AutoInstaller/Installation/GitHubRelease.cs

This file was deleted.

Loading
Loading