update installer

This commit is contained in:
Zack Rauen 2017-12-19 00:33:44 -05:00
parent 6985c24009
commit b30eaeae3a
11 changed files with 203 additions and 57 deletions

View File

@ -12,6 +12,8 @@
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -41,7 +43,11 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="asardotnet">
<HintPath>..\..\..\..\WindowsInstaller\asardotnet.dll</HintPath>
<HintPath>asardotnet.dll</HintPath>
</Reference>
<Reference Include="Costura, Version=1.6.2.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.1.6.2\lib\dotnet\Costura.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -145,9 +151,19 @@
</ItemGroup>
<ItemGroup>
<Content Include="BetterDiscord-icon.ico" />
<None Include="FodyWeavers.xml" />
<Content Include="Resources\BetterDiscord-icon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.2.0.0\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.2.0.0\build\dotnet\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.2.0.0\build\dotnet\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.2.0.0\build\dotnet\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets'))" />
</Target>
<Import Project="..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets" Condition="Exists('..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Costura />
</Weavers>

View File

@ -14,6 +14,10 @@ namespace BetterDiscordWI {
public bool RestartDiscord = false;
public string Sha;
public bool Finished = false;
public bool ZeresFork = false;
public string DiscordVersion = "Discord";
public bool DesktopModule = false;
public string DiscordInstallPath;
public XmlNodeList ResourceList;

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Costura.Fody" version="1.6.2" targetFramework="net451" developmentDependency="true" />
<package id="Fody" version="2.0.0" targetFramework="net451" developmentDependency="true" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net451" />
</packages>

View File

@ -36,6 +36,7 @@
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.tbPath = new BetterDiscordWI.components.CTextBox();
this.checkBox3 = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// label1
@ -119,10 +120,22 @@
this.tbPath.Size = new System.Drawing.Size(377, 26);
this.tbPath.TabIndex = 4;
//
// checkBox3
//
this.checkBox3.AutoSize = true;
this.checkBox3.Location = new System.Drawing.Point(23, 187);
this.checkBox3.Name = "checkBox3";
this.checkBox3.Size = new System.Drawing.Size(149, 17);
this.checkBox3.TabIndex = 9;
this.checkBox3.Text = "Use Zere\'s (unofficial) fork";
this.checkBox3.UseVisualStyleBackColor = true;
this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged);
//
// Panel1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.checkBox3);
this.Controls.Add(this.checkBox2);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.cbRestart);
@ -133,6 +146,7 @@
this.Controls.Add(this.label1);
this.Name = "Panel1";
this.Size = new System.Drawing.Size(524, 258);
this.Load += new System.EventHandler(this.Panel1_Load);
this.ResumeLayout(false);
this.PerformLayout();
@ -148,5 +162,6 @@
internal components.CTextBox tbPath;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox3;
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace BetterDiscordWI.panels {
@ -28,6 +29,7 @@ namespace BetterDiscordWI.panels {
GetParent().DiscordPath = tbPath.Text;
GetParent().RestartDiscord = cbRestart.Checked;
GetParent().SwitchPanel(2);
GetParent().ZeresFork = checkBox3.Checked;
}
public void BtnPrev() {
@ -65,12 +67,47 @@ namespace BetterDiscordWI.panels {
dirPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\Discord";
}
if (!Directory.Exists(dirPath)) return;
string[] directories = Directory.GetDirectories(dirPath);
if (checkBox1.Checked)
GetParent().DiscordVersion = "DiscordCanary";
else if (checkBox2.Checked)
GetParent().DiscordVersion = "DiscordPTB";
else
GetParent().DiscordVersion = "Discord";
if (!Directory.Exists(dirPath)) return;
GetParent().DesktopModule = false;
string otherDir = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{GetParent().DiscordVersion.ToLower()}";
if (Directory.Exists(otherDir))
{
string[] dirs = Directory.GetDirectories(otherDir);
string maxVersion = dirs[0];
Regex matcher = new Regex(@"[0-9]+\.[0-9]+\.[0-9]+");
foreach (string s in dirs)
{
Debug.Print(s);
if (!matcher.IsMatch(s))
continue;
if (string.CompareOrdinal(s, maxVersion) > 0)
{
maxVersion = s;
}
}
string coreModule = $"{maxVersion}\\modules\\discord_desktop_core";
if (Directory.Exists(coreModule))
{
tbPath.Text = coreModule;
GetParent().DesktopModule = true;
}
}
string[] directories = Directory.GetDirectories(dirPath);
string highestVersion = null;
foreach(string s in directories) {
foreach (string s in directories) {
Debug.Print(s);
if(!s.Contains("app-"))
continue;
@ -84,7 +121,20 @@ namespace BetterDiscordWI.panels {
}
}
tbPath.Text = highestVersion;
GetParent().DiscordInstallPath = highestVersion;
if (!GetParent().DesktopModule)
{
tbPath.Text = highestVersion;
}
}
private void Panel1_Load(object sender, EventArgs e)
{
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
}
}
}

View File

@ -13,6 +13,7 @@ namespace BetterDiscordWI.panels {
public partial class Panel2: UserControl, IPanel {
private string _dataPath, _tempPath;
private Utils _utils;
private bool discord_core_module = false;
public Panel2() {
InitializeComponent();
@ -80,7 +81,9 @@ namespace BetterDiscordWI.panels {
Directory.CreateDirectory(_tempPath);
DownloadResource("BetterDiscord.zip", "https://github.com/Jiiks/BetterDiscordApp/archive/stable16.zip");
String fork = "Jiiks";
if (GetParent().ZeresFork) fork = "rauenzi";
DownloadResource("BetterDiscord.zip", $"https://github.com/{fork}/BetterDiscordApp/archive/stable16.zip");
while(!File.Exists($"{_tempPath}\\BetterDiscord.zip")) {
Debug.Print("Waiting for download");
@ -102,7 +105,7 @@ namespace BetterDiscordWI.panels {
private void DeleteDirs() {
int errors = 0;
Thread t = new Thread(() => {
Thread t1 = new Thread(() => {
string dir = $"{GetParent().DiscordPath}\\resources\\app";
if(Directory.Exists(dir)) {
@ -120,7 +123,7 @@ namespace BetterDiscordWI.panels {
Debug.Print("Waiting for direl");
Thread.Sleep(100);
}
//C:\Users\Zack\AppData\Roaming\discordcanary
if (!Directory.Exists($"{GetParent().DiscordPath}\\resources\\node_modules\\")) {
Debug.Print("node_modules doesn't exist, creating");
AppendLog("node_modules doesn't exist, creating");
@ -160,15 +163,67 @@ namespace BetterDiscordWI.panels {
try {
Splice();
} catch {
AppendLog("Error: Extracting app.asar: Newtonsoft.Json.dll might not be present in the Installer Folder. Installation cannot Continue.");
AppendLog("Error: Splicing index.js: Newtonsoft.Json.dll might not be present in the Installer Folder. Installation cannot Continue.");
errors = 1;
Finalize(errors);
}
}
});
Thread t2 = new Thread(() => {
string dir = $"{GetParent().DiscordPath}\\app\\mainScreen.js";
t.Start();
if (File.Exists(dir + ".old") && File.Exists(dir))
{
AppendLog($"Restoring original {dir}");
File.Delete(dir);
while (File.Exists(dir))
{
Debug.Print("Waiting for direl");
Thread.Sleep(100);
}
File.Move(dir + ".old", dir);
}
AppendLog($"Making backup of {dir}");
File.Copy(dir, dir + ".old");
dir = $"{GetParent().DiscordPath}\\node_modules\\BetterDiscord";
if (Directory.Exists(dir))
{
AppendLog($"Deleting {dir}");
Directory.Delete(dir, true);
}
while (Directory.Exists(dir))
{
Debug.Print("Waiting for direl");
Thread.Sleep(100);
}
if (errors == 0)
{
AppendLog("Moving BetterDiscord to node_modules");
Directory.Move($"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\BetterDiscord\\temp\\BetterDiscordApp-stable16", dir);
try
{
Splice();
}
catch
{
AppendLog("Error: Splicing mainScreen.js: Newtonsoft.Json.dll might not be present in the Installer Folder. Installation cannot Continue.");
errors = 1;
Finalize(errors);
}
}
});
if (GetParent().DesktopModule) t2.Start();
else t1.Start();
}
private void DownloadResource(string resource, string url) {
@ -179,59 +234,63 @@ namespace BetterDiscordWI.panels {
webClient.DownloadFile(new Uri(url), $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\BetterDiscord\\temp\\{resource}");
}
private void Splice() {
private void Splice()
{
string indexloc = null;
if(File.Exists($"{GetParent().DiscordPath}\\resources\\app\\app\\index.js"))
if (File.Exists($"{GetParent().DiscordPath}\\resources\\app\\index.js"))
{
//Normal path
indexloc = $"{GetParent().DiscordPath}\\resources\\app\\app\\index.js";
} else if (File.Exists($"{GetParent().DiscordPath}\\resources\\app\\index.js"))
{
//Canary 0.0.138 changed path to app\\index.js
indexloc = $"{GetParent().DiscordPath}\\resources\\app\\index.js";
}
if(indexloc == null)
else if (File.Exists($"{GetParent().DiscordPath}\\app\\mainScreen.js"))
{
AppendLog($"Error: index.js not found");
indexloc = $"{GetParent().DiscordPath}\\app\\mainScreen.js";
}
if (indexloc == null)
{
AppendLog($"Error: index.js or mainScreen.js not found");
Finalize(1);
return;
}
if(!File.Exists(@"splice"))
{
AppendLog($"Error: splice install file not found, this should be included with the installer.");
Finalize(1);
return;
}
//if (!File.Exists(@"splice"))
//{
// AppendLog($"Error: splice install file not found, this should be included with the installer.");
// Finalize(1);
// return;
//}
Thread t = new Thread(() => {
List<string> lines = new List<string>();
AppendLog("Spicing index");
using(FileStream fs = new FileStream(indexloc, FileMode.Open)) {
using(StreamReader reader = new StreamReader(fs)) {
AppendLog("Splicing main file");
using (FileStream fs = new FileStream(indexloc, FileMode.Open))
{
using (StreamReader reader = new StreamReader(fs))
{
string line = "";
while((line = reader.ReadLine()) != null) {
//if(GetParent().DiscordPath.Contains("Discord\\")) {
//if(GetParent().DiscordPath.Contains("DiscordCanary\\")) {
//if(GetParent().DiscordPath.Contains("DiscordPTB\\")) {
if(line.Replace(" ", "").Contains("var_fs=")) {
while ((line = reader.ReadLine()) != null)
{
if (line.Replace(" ", "").Contains("var_url="))
{
lines.Add(line);
lines.Add("var _betterDiscord = require('betterdiscord');");
lines.Add("var _betterDiscord2;");
} else if(line.Replace(" ", "").Contains("mainWindow=new")) {
}
else if (line.Replace(" ", "").Contains("mainWindow=new"))
{
lines.Add(line);
lines.Add(File.ReadAllText(@"splice"));
} else {
lines.Add("_betterDiscord2 = new _betterDiscord.BetterDiscord(mainWindow);");
}
else
{
lines.Add(line);
}
//}
}
}
}
AppendLog("Writing index");
AppendLog("Writing injection");
File.WriteAllLines(indexloc, lines.ToArray());
@ -239,27 +298,31 @@ namespace BetterDiscordWI.panels {
int errors = 0;
string curPath = $"{GetParent().DiscordPath}\\resources\\app\\app\\index.js";
string curPath2 = $"{GetParent().DiscordPath}\\resources\\app\\index.js";
string curPath = $"{GetParent().DiscordPath}\\resources\\app\\index.js";
string curPath2 = $"{GetParent().DiscordPath}\\app\\mainScreen.js";
if (!File.Exists(curPath) && !File.Exists(curPath2))
{
AppendLog($"ERROR: index.js not found in {curPath} or {curPath2}");
AppendLog($"ERROR: index.js or mainScreen.js not found in {curPath} or {curPath2}");
errors++;
}
curPath = $"{GetParent().DiscordPath}\\resources\\node_modules\\BetterDiscord";
if (GetParent().DesktopModule)
curPath = $"{GetParent().DiscordPath}\\node_modules\\BetterDiscord";
else
curPath = $"{GetParent().DiscordPath}\\resources\\node_modules\\BetterDiscord";
if(!Directory.Exists(curPath)) {
if (!Directory.Exists(curPath))
{
AppendLog($"ERROR: DIRECTORY: {curPath} DOES NOT EXIST!");
errors++;
}
string basePath = $"{GetParent().DiscordPath}\\resources\\node_modules\\BetterDiscord";
string[] bdFiles = { "\\package.json", "\\betterdiscord.js", "\\lib\\BetterDiscord.js", "\\lib\\config.json", "\\lib\\Utils.js" };
foreach(string s in bdFiles.Where(s => !File.Exists(basePath + s))) {
AppendLog($"ERROR: FILE: {basePath}{s} DOES NOT EXIST");
foreach (string s in bdFiles.Where(s => !File.Exists(curPath + s)))
{
AppendLog($"ERROR: FILE: {curPath}{s} DOES NOT EXIST");
errors++;
}
Finalize(errors);
@ -278,15 +341,7 @@ namespace BetterDiscordWI.panels {
});
if(GetParent().RestartDiscord) {
if(GetParent().DiscordPath.Contains("\\Discord\\")) {
Process.Start($"{GetParent().DiscordPath}\\Discord.exe");
}
if(GetParent().DiscordPath.Contains("\\DiscordCanary\\")) {
Process.Start($"{GetParent().DiscordPath}\\DiscordCanary.exe");
}
if(GetParent().DiscordPath.Contains("\\DiscordPTB\\")) {
Process.Start($"{GetParent().DiscordPath}\\DiscordPTB.exe");
}
Process.Start($"{GetParent().DiscordInstallPath}\\{GetParent().DiscordVersion}.exe");
}
}