Skip to content

Commit 2084388

Browse files
authored
Merge pull request #547 from Jaskar/master
#245 - Windows Installer for 3ds Max and Maya exporters. v0.2
2 parents 9a8d675 + 90f5fdd commit 2084388

17 files changed

+3862
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29009.5
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BabylonJS_Installer", "BabylonJS_Installer\BabylonJS_Installer.csproj", "{45FD7CBD-DB3D-4980-8A85-9DEF5DDFB66D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{45FD7CBD-DB3D-4980-8A85-9DEF5DDFB66D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{45FD7CBD-DB3D-4980-8A85-9DEF5DDFB66D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{45FD7CBD-DB3D-4980-8A85-9DEF5DDFB66D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{45FD7CBD-DB3D-4980-8A85-9DEF5DDFB66D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {72B66FA2-FF79-4ABE-B754-22FF5D390CEB}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{45FD7CBD-DB3D-4980-8A85-9DEF5DDFB66D}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>BabylonJS_Installer</RootNamespace>
10+
<AssemblyName>BabylonJS_Exporters</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>0</WarningLevel>
34+
</PropertyGroup>
35+
<PropertyGroup>
36+
<ApplicationIcon>Img\BJS_logo_4.0.ico</ApplicationIcon>
37+
</PropertyGroup>
38+
<PropertyGroup>
39+
<NoWin32Manifest>true</NoWin32Manifest>
40+
</PropertyGroup>
41+
<PropertyGroup>
42+
<SignManifests>false</SignManifests>
43+
</PropertyGroup>
44+
<PropertyGroup>
45+
<SignAssembly>false</SignAssembly>
46+
</PropertyGroup>
47+
<ItemGroup>
48+
<Reference Include="System" />
49+
<Reference Include="System.Core" />
50+
<Reference Include="System.IO.Compression" />
51+
<Reference Include="System.IO.Compression.FileSystem" />
52+
<Reference Include="System.Xml.Linq" />
53+
<Reference Include="System.Data.DataSetExtensions" />
54+
<Reference Include="Microsoft.CSharp" />
55+
<Reference Include="System.Data" />
56+
<Reference Include="System.Deployment" />
57+
<Reference Include="System.Drawing" />
58+
<Reference Include="System.Net.Http" />
59+
<Reference Include="System.Windows.Forms" />
60+
<Reference Include="System.Xml" />
61+
</ItemGroup>
62+
<ItemGroup>
63+
<Compile Include="Downloader.cs" />
64+
<Compile Include="Form1.cs">
65+
<SubType>Form</SubType>
66+
</Compile>
67+
<Compile Include="Form1.Designer.cs">
68+
<DependentUpon>Form1.cs</DependentUpon>
69+
</Compile>
70+
<Compile Include="Program.cs" />
71+
<Compile Include="Properties\AssemblyInfo.cs" />
72+
<Compile Include="SoftwareChecker.cs" />
73+
<EmbeddedResource Include="Form1.resx">
74+
<DependentUpon>Form1.cs</DependentUpon>
75+
</EmbeddedResource>
76+
<EmbeddedResource Include="Properties\Resources.resx">
77+
<Generator>ResXFileCodeGenerator</Generator>
78+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
79+
<SubType>Designer</SubType>
80+
</EmbeddedResource>
81+
<Compile Include="Properties\Resources.Designer.cs">
82+
<AutoGen>True</AutoGen>
83+
<DependentUpon>Resources.resx</DependentUpon>
84+
<DesignTime>True</DesignTime>
85+
</Compile>
86+
<None Include="Properties\Settings.settings">
87+
<Generator>SettingsSingleFileGenerator</Generator>
88+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
89+
</None>
90+
<Compile Include="Properties\Settings.Designer.cs">
91+
<AutoGen>True</AutoGen>
92+
<DependentUpon>Settings.settings</DependentUpon>
93+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
94+
</Compile>
95+
</ItemGroup>
96+
<ItemGroup>
97+
<None Include="App.config" />
98+
</ItemGroup>
99+
<ItemGroup />
100+
<ItemGroup>
101+
<Content Include="Img\BJS_logo_4.0.ico" />
102+
<Content Include="Img\BJS_logo_4.0.jpg" />
103+
<Content Include="Img\BJS_logo_4.0.png" />
104+
</ItemGroup>
105+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
106+
</Project>
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
using System;
2+
using System.IO;
3+
using System.IO.Compression;
4+
using System.Net;
5+
using System.Net.Http;
6+
7+
namespace BabylonJS_Installer
8+
{
9+
class Downloader
10+
{
11+
private readonly string url_github = "github.com";
12+
private readonly string url_download = "https://github.com/BabylonJS/Exporters/releases/download";
13+
private readonly string url_github_API_releases = "https://api.github.com/repos/BabylonJS/Exporters/releases";
14+
private string software = "";
15+
private string version = "";
16+
private string installDir = "";
17+
private string latestRelease = "";
18+
19+
public MainForm form;
20+
21+
public void init(string software, string version, string installDir)
22+
{
23+
this.form.goTab("");
24+
this.form.log("\n----- INSTALLING / DOWNLOADING " + software + " v" + version + " EXPORTER -----\n");
25+
26+
this.software = software;
27+
this.version = version;
28+
this.installDir = installDir;
29+
30+
if (this.pingSite(this.url_github))
31+
{
32+
this.form.log("Info : Connection to GitHub OK");
33+
if (this.latestRelease == "")
34+
this.getLatestRelease();
35+
else
36+
this.download(this.latestRelease);
37+
38+
}
39+
}
40+
41+
private bool pingSite(string url_toTest)
42+
{
43+
44+
var ping = new System.Net.NetworkInformation.Ping();
45+
46+
try
47+
{
48+
var result = ping.Send(url_toTest);
49+
50+
if (result.Status != System.Net.NetworkInformation.IPStatus.Success)
51+
{
52+
this.form.log("Error : Can't reach Github.");
53+
return false;
54+
}
55+
else
56+
{
57+
return true;
58+
}
59+
}
60+
catch (Exception ex)
61+
{
62+
this.form.log(
63+
"Can't reach Github.\n"
64+
+ "Error : \n"
65+
+ "\"" + ex.Message + "\""
66+
);
67+
return false;
68+
}
69+
}
70+
71+
private async void getLatestRelease()
72+
{
73+
this.form.log("Trying to get the last version ...");
74+
75+
try
76+
{
77+
// Old way with Octokit (nuget package)
78+
//var ghClient = new GitHubClient(new ProductHeaderValue("BJS_Installer"));
79+
//var lastRelease = await ghClient.Repository.Release.GetAll("BabylonJS", "Exporters");
80+
//if (lastRelease[0].Prerelease == true)
81+
//{
82+
//this.latestRelease = lastRelease[0].HtmlUrl.Substring(lastRelease[0].HtmlUrl.LastIndexOf("/"));
83+
//this.form.log("Last release package is : " + this.latestRelease + "\n");
84+
//this.download(this.latestRelease);
85+
//}
86+
87+
HttpClient client = new HttpClient();
88+
client.DefaultRequestHeaders.Add("User-Agent", "BJS_Installer");
89+
HttpResponseMessage response = await client.GetAsync(this.url_github_API_releases);
90+
91+
// TO DO - Parse the JSON in a more beautiful way...
92+
String responseBody = await response.Content.ReadAsStringAsync();
93+
String lastestReleaseInfos = responseBody.Substring(responseBody.IndexOf("\"prerelease\":") + "\"prerelease\":".Length);
94+
//Ensure we are on Rrerelease version
95+
if (lastestReleaseInfos.StartsWith("true"))
96+
{
97+
//We parse the array to find the dowload URL
98+
this.latestRelease = lastestReleaseInfos.Substring(lastestReleaseInfos.IndexOf("\"browser_download_url\":") + "\"browser_download_url\": ".Length);
99+
100+
// We split, remove & substrings to get only the URL starting with https://github.com and lasting with preRelease version
101+
this.latestRelease = this.latestRelease.Split('"')[0];
102+
this.latestRelease = this.latestRelease.Remove(this.latestRelease.LastIndexOf("/"));
103+
this.latestRelease = this.latestRelease.Substring(this.latestRelease.LastIndexOf("/"));
104+
this.download(this.latestRelease);
105+
}
106+
else
107+
this.form.log("Error : Can't find the last release package.");
108+
}
109+
catch(Exception ex)
110+
{
111+
this.form.log(
112+
"Can't reach the GitHub API\n"
113+
+ "Please, try in 1 hour. (The API limitation is 60 queries / hour\n"
114+
+ "Error message : \n"
115+
+ "\"" + ex.Message + "\""
116+
);
117+
}
118+
}
119+
120+
private void download(string releaseName)
121+
{
122+
this.form.log(
123+
"Downloading files : \n"
124+
+ this.url_download + releaseName + "/" + this.software + "_" + this.version + ".zip"
125+
);
126+
127+
// Download the zip
128+
try
129+
{
130+
using (var client = new WebClient())
131+
{
132+
client.DownloadFile(
133+
this.url_download + releaseName + "/" + this.software + "_" + this.version + ".zip",
134+
this.software + "_" + this.version + ".zip"
135+
);
136+
}
137+
}
138+
catch (Exception ex)
139+
{
140+
this.form.log(
141+
"Can't download the files.\n"
142+
+ "Error message : \n"
143+
+ "\"" + ex.Message + "\""
144+
);
145+
}
146+
147+
this.downloadComplete();
148+
}
149+
150+
private void downloadComplete()
151+
{
152+
this.form.log(
153+
"Download complete.\n"
154+
+ "Extracting files ..."
155+
);
156+
157+
try
158+
{
159+
// This way can't rewrite files
160+
//ZipFile.ExtractToDirectory(
161+
// this.software + "_" + this.version + ".zip",
162+
// this.installDir
163+
// );
164+
165+
String zipFileName = this.software + "_" + this.version + ".zip";
166+
using (ZipArchive myZip = ZipFile.OpenRead(zipFileName))
167+
{
168+
foreach (ZipArchiveEntry entry in myZip.Entries)
169+
{
170+
entry.ExtractToFile(this.installDir + "/" + entry.Name, true);
171+
}
172+
}
173+
}
174+
catch(Exception ex)
175+
{
176+
this.form.log(
177+
"Can't extract the files.\n"
178+
+ "If you're not, please try to run this tool in ADMINISTRATOR MODE. It's necessary to extract the files in \"Program Files\" folder (or other protected folders).\n"
179+
+ "Error message : \n"
180+
+ "\"" + ex.Message + "\""
181+
);
182+
}
183+
184+
this.form.log(
185+
"Extraction complete.\n"
186+
+ "Deleting temporary files ..."
187+
);
188+
189+
try
190+
{
191+
File.Delete(this.software + "_" + this.version + ".zip");
192+
}
193+
catch (Exception ex)
194+
{
195+
this.form.log(
196+
"Can't delete temporary files.\n"
197+
+ "Error message : \n"
198+
+ "\"" + ex.Message + "\""
199+
);
200+
}
201+
202+
this.form.log("\n----- " + this.software + " " + this.version + " EXPORTER UP TO DATE ----- \n");
203+
}
204+
}
205+
}

0 commit comments

Comments
 (0)