This commit is contained in:
Bitl 2019-10-11 11:03:30 -07:00
parent aef3b56f4b
commit 77d03c9649
10 changed files with 1209 additions and 1041 deletions

View File

@ -8,7 +8,7 @@
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>NovetusCMD</RootNamespace> <RootNamespace>NovetusCMD</RootNamespace>
<AssemblyName>NovetusCMD</AssemblyName> <AssemblyName>NovetusCMD</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<NoWin32Manifest>False</NoWin32Manifest> <NoWin32Manifest>False</NoWin32Manifest>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
@ -17,6 +17,7 @@
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath> <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<ApplicationIcon>Resources\NovetusIcon.ico</ApplicationIcon> <ApplicationIcon>Resources\NovetusIcon.ico</ApplicationIcon>
<TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> <PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
@ -43,6 +44,12 @@
<DefineConstants>TRACE;NOVETUS_APPS</DefineConstants> <DefineConstants>TRACE;NOVETUS_APPS</DefineConstants>
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath> <BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.CSharp"> <Reference Include="Microsoft.CSharp">
<RequiredTargetFramework>4.0</RequiredTargetFramework> <RequiredTargetFramework>4.0</RequiredTargetFramework>
@ -59,6 +66,8 @@
<RequiredTargetFramework>3.5</RequiredTargetFramework> <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq"> <Reference Include="System.Xml.Linq">

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup> </startup>
</configuration> </configuration>

View File

@ -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);
}
}
}

View File

@ -11,6 +11,8 @@ using System;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Diagnostics; using System.Diagnostics;
using System.IO.Compression;
using System.IO;
public static class RichTextBoxExtensions public static class RichTextBoxExtensions
{ {
@ -48,4 +50,36 @@ public static class StringExtensions
return false; return false;
return source.IndexOf(toCheck, comp) >= 0; 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);
}
}
} }

View File

@ -9,6 +9,7 @@
<Import_RootNamespace>NovetusFuncs</Import_RootNamespace> <Import_RootNamespace>NovetusFuncs</Import_RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)AddonLoader.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ClientScript.cs" /> <Compile Include="$(MSBuildThisFileDirectory)ClientScript.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CodeExtensions.cs" /> <Compile Include="$(MSBuildThisFileDirectory)CodeExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CryptoRandom.cs" /> <Compile Include="$(MSBuildThisFileDirectory)CryptoRandom.cs" />

File diff suppressed because it is too large Load Diff

View File

@ -1473,5 +1473,22 @@ namespace NovetusLauncher
treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.Map, treeView1.Nodes); treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.Map, treeView1.Nodes);
treeView1.Focus(); 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);
}
}
} }

View File

@ -7,7 +7,7 @@
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<RootNamespace>NovetusLauncher</RootNamespace> <RootNamespace>NovetusLauncher</RootNamespace>
<AssemblyName>Novetus</AssemblyName> <AssemblyName>Novetus</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile> <TargetFrameworkProfile>
</TargetFrameworkProfile> </TargetFrameworkProfile>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
@ -48,6 +48,12 @@
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath> <BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
<StartAction>Project</StartAction> <StartAction>Project</StartAction>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Mono.Nat"> <Reference Include="Mono.Nat">
<HintPath>..\packages\Mono.Nat.1.2.24.0\lib\net40\Mono.Nat.dll</HintPath> <HintPath>..\packages\Mono.Nat.1.2.24.0\lib\net40\Mono.Nat.dll</HintPath>
@ -61,6 +67,8 @@
<RequiredTargetFramework>3.5</RequiredTargetFramework> <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq"> <Reference Include="System.Xml.Linq">

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup> </startup>
</configuration> </configuration>