Addons!
This commit is contained in:
parent
aef3b56f4b
commit
77d03c9649
Binary file not shown.
|
|
@ -8,7 +8,7 @@
|
|||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>NovetusCMD</RootNamespace>
|
||||
<AssemblyName>NovetusCMD</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<NoWin32Manifest>False</NoWin32Manifest>
|
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ApplicationIcon>Resources\NovetusIcon.ico</ApplicationIcon>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
|
|
@ -43,6 +44,12 @@
|
|||
<DefineConstants>TRACE;NOVETUS_APPS</DefineConstants>
|
||||
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
|
|
@ -59,6 +66,8 @@
|
|||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq">
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
|
||||
public class AddonLoader
|
||||
{
|
||||
private OpenFileDialog openFileDialog1;
|
||||
public string installOutcome = "";
|
||||
public int fileListDisplay = 0;
|
||||
|
||||
public AddonLoader()
|
||||
{
|
||||
openFileDialog1 = new OpenFileDialog()
|
||||
{
|
||||
FileName = "Select an addon .zip file",
|
||||
Filter = "Compressed zip files (*.zip)|*.zip",
|
||||
Title = "Open addon .zip"
|
||||
};
|
||||
}
|
||||
|
||||
public void LoadAddon()
|
||||
{
|
||||
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
int filecount = 0;
|
||||
string filelist = "";
|
||||
|
||||
using (Stream str = openFileDialog1.OpenFile())
|
||||
{
|
||||
using (ZipArchive archive = new ZipArchive(str))
|
||||
{
|
||||
filecount = archive.Entries.Count;
|
||||
|
||||
ZipArchiveEntry[] entries = archive.Entries.Take(fileListDisplay).ToArray();
|
||||
|
||||
foreach (ZipArchiveEntry entry in entries)
|
||||
{
|
||||
filelist += entry.FullName + Environment.NewLine;
|
||||
}
|
||||
archive.ExtractToDirectory(GlobalVars.BasePath, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (filecount > fileListDisplay)
|
||||
{
|
||||
installOutcome = "Addon " + openFileDialog1.SafeFileName + " installed! " + filecount + " files copied!" + Environment.NewLine + "Files added/modified:" + Environment.NewLine + Environment.NewLine + filelist + Environment.NewLine + "and " + (filecount - fileListDisplay) + " more files!";
|
||||
}
|
||||
else
|
||||
{
|
||||
installOutcome = "Addon " + openFileDialog1.SafeFileName + " installed! " + filecount + " files copied!" + Environment.NewLine + "Files added/modified:" + Environment.NewLine + Environment.NewLine + filelist;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
installOutcome = "Error when installing addon: " + ex.Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CopyStream(Stream source, Stream dest)
|
||||
{
|
||||
int n;
|
||||
var buf = new byte[2048];
|
||||
while ((n = source.Read(buf, 0, buf.Length)) > 0)
|
||||
{
|
||||
dest.Write(buf, 0, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,8 @@ using System;
|
|||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using System.Diagnostics;
|
||||
using System.IO.Compression;
|
||||
using System.IO;
|
||||
|
||||
public static class RichTextBoxExtensions
|
||||
{
|
||||
|
|
@ -48,4 +50,36 @@ public static class StringExtensions
|
|||
return false;
|
||||
return source.IndexOf(toCheck, comp) >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ZipArchiveExtensions
|
||||
{
|
||||
public static void ExtractToDirectory(this ZipArchive archive, string destinationDirectoryName, bool overwrite)
|
||||
{
|
||||
if (!overwrite)
|
||||
{
|
||||
archive.ExtractToDirectory(destinationDirectoryName);
|
||||
return;
|
||||
}
|
||||
|
||||
DirectoryInfo di = Directory.CreateDirectory(destinationDirectoryName);
|
||||
string destinationDirectoryFullPath = di.FullName;
|
||||
|
||||
foreach (ZipArchiveEntry file in archive.Entries)
|
||||
{
|
||||
string completeFileName = Path.GetFullPath(Path.Combine(destinationDirectoryFullPath, file.FullName));
|
||||
|
||||
if (!completeFileName.StartsWith(destinationDirectoryFullPath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new IOException("Trying to extract file outside of destination directory. See this link for more info: https://snyk.io/research/zip-slip-vulnerability");
|
||||
}
|
||||
|
||||
if (file.Name == "")
|
||||
{// Assuming Empty for Directory
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(completeFileName));
|
||||
continue;
|
||||
}
|
||||
file.ExtractToFile(completeFileName, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
<Import_RootNamespace>NovetusFuncs</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)AddonLoader.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ClientScript.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)CodeExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)CryptoRandom.cs" />
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1473,5 +1473,22 @@ namespace NovetusLauncher
|
|||
treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.Map, treeView1.Nodes);
|
||||
treeView1.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
private void button25_Click(object sender, EventArgs e)
|
||||
{
|
||||
AddonLoader addon = new AddonLoader();
|
||||
addon.fileListDisplay = 10;
|
||||
try
|
||||
{
|
||||
addon.LoadAddon();
|
||||
ConsolePrint("AddonLoader - " + addon.installOutcome, 3);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
ConsolePrint("AddonLoader - " + addon.installOutcome, 2);
|
||||
}
|
||||
|
||||
MessageBox.Show(addon.installOutcome);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>NovetusLauncher</RootNamespace>
|
||||
<AssemblyName>Novetus</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
|
|
@ -48,6 +48,12 @@
|
|||
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
|
||||
<StartAction>Project</StartAction>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Mono.Nat">
|
||||
<HintPath>..\packages\Mono.Nat.1.2.24.0\lib\net40\Mono.Nat.dll</HintPath>
|
||||
|
|
@ -61,6 +67,8 @@
|
|||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq">
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
|
|
|||
Loading…
Reference in New Issue