Skip to content

Commit 6156684

Browse files
author
VixikHD
committed
Initial commit
0 parents  commit 6156684

21 files changed

+428
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

App.config

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.6.1" />
5+
</startup>
6+
</configuration>

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 VixikHD
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

PocketMineInstaller.csproj

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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>{6F3C2693-BC0D-412B-8C01-87DEA5AC9977}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>PocketMineInstaller</RootNamespace>
10+
<AssemblyName>PocketMineInstaller</AssemblyName>
11+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
<PublishUrl>publish\</PublishUrl>
16+
<Install>true</Install>
17+
<InstallFrom>Disk</InstallFrom>
18+
<UpdateEnabled>false</UpdateEnabled>
19+
<UpdateMode>Foreground</UpdateMode>
20+
<UpdateInterval>7</UpdateInterval>
21+
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
22+
<UpdatePeriodically>false</UpdatePeriodically>
23+
<UpdateRequired>false</UpdateRequired>
24+
<MapFileExtensions>true</MapFileExtensions>
25+
<ApplicationRevision>0</ApplicationRevision>
26+
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
27+
<IsWebBootstrapper>false</IsWebBootstrapper>
28+
<UseApplicationTrust>false</UseApplicationTrust>
29+
<BootstrapperEnabled>true</BootstrapperEnabled>
30+
</PropertyGroup>
31+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
32+
<PlatformTarget>AnyCPU</PlatformTarget>
33+
<DebugSymbols>true</DebugSymbols>
34+
<DebugType>full</DebugType>
35+
<Optimize>false</Optimize>
36+
<OutputPath>bin\Debug\</OutputPath>
37+
<DefineConstants>DEBUG;TRACE</DefineConstants>
38+
<ErrorReport>prompt</ErrorReport>
39+
<WarningLevel>4</WarningLevel>
40+
</PropertyGroup>
41+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
42+
<PlatformTarget>AnyCPU</PlatformTarget>
43+
<DebugType>pdbonly</DebugType>
44+
<Optimize>true</Optimize>
45+
<OutputPath>bin\Release\</OutputPath>
46+
<DefineConstants>TRACE</DefineConstants>
47+
<ErrorReport>prompt</ErrorReport>
48+
<WarningLevel>4</WarningLevel>
49+
</PropertyGroup>
50+
<PropertyGroup>
51+
<ApplicationIcon>icon.ico</ApplicationIcon>
52+
</PropertyGroup>
53+
<ItemGroup>
54+
<Reference Include="System" />
55+
<Reference Include="System.Core" />
56+
<Reference Include="System.IO.Compression" />
57+
<Reference Include="System.IO.Compression.FileSystem" />
58+
<Reference Include="System.Xml.Linq" />
59+
<Reference Include="System.Data.DataSetExtensions" />
60+
<Reference Include="Microsoft.CSharp" />
61+
<Reference Include="System.Data" />
62+
<Reference Include="System.Net.Http" />
63+
<Reference Include="System.Xml" />
64+
</ItemGroup>
65+
<ItemGroup>
66+
<Compile Include="Program.cs" />
67+
<Compile Include="Properties\AssemblyInfo.cs" />
68+
</ItemGroup>
69+
<ItemGroup>
70+
<None Include="App.config" />
71+
</ItemGroup>
72+
<ItemGroup>
73+
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
74+
<Visible>False</Visible>
75+
<ProductName>Microsoft .NET Framework 4.6.1 %28x86 a x64%29</ProductName>
76+
<Install>true</Install>
77+
</BootstrapperPackage>
78+
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
79+
<Visible>False</Visible>
80+
<ProductName>.NET Framework 3.5 SP1</ProductName>
81+
<Install>false</Install>
82+
</BootstrapperPackage>
83+
</ItemGroup>
84+
<ItemGroup>
85+
<WCFMetadata Include="Connected Services\" />
86+
</ItemGroup>
87+
<ItemGroup>
88+
<Content Include="icon.ico" />
89+
</ItemGroup>
90+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
91+
</Project>

PocketMineInstaller.csproj.user

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<PublishUrlHistory>publish\</PublishUrlHistory>
5+
<InstallUrlHistory />
6+
<SupportUrlHistory />
7+
<UpdateUrlHistory />
8+
<BootstrapperUrlHistory />
9+
<ErrorReportUrlHistory />
10+
<FallbackCulture>cs-CZ</FallbackCulture>
11+
<VerifyUploadedFiles>false</VerifyUploadedFiles>
12+
</PropertyGroup>
13+
</Project>

Program.cs

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
using System;
2+
using System.Linq;
3+
using System.Net;
4+
using System.IO.Compression;
5+
using System.Diagnostics;
6+
7+
namespace PocketMineInstaller
8+
{
9+
class Program
10+
{
11+
12+
static string windowsPhpURL = "https://jenkins.pmmp.io/job/PHP-7.2-Aggregate/lastBuild/artifact/PHP-7.2-Windows-x64.zip";
13+
14+
static void Main(string[] args)
15+
{
16+
Console.ForegroundColor = ConsoleColor.White;
17+
Console.Out.WriteLine("-> PocketMine console installator by CzechPMDevs");
18+
Console.Out.WriteLine("-> Type 'help' to display installator commands.");
19+
Console.Out.WriteLine("");
20+
Console.ForegroundColor = ConsoleColor.Gray;
21+
22+
Console.Title = "PocketMine-MP installer by CzechPMDevs";
23+
24+
string output = "";
25+
while(null != (output = Console.ReadLine())) {
26+
HandleCommand(output);
27+
}
28+
}
29+
30+
static void HandleCommand(string command)
31+
{
32+
string[] args = command.Split(' ');
33+
int argsCount = args.Count();
34+
if(argsCount < 1) {
35+
Console.Out.WriteLine("Type 'help' to display PocketMine installer commands.");
36+
Console.Out.WriteLine(argsCount);
37+
return;
38+
}
39+
40+
switch(args[0]) {
41+
case "help":
42+
Console.Out.WriteLine("--- PocketMine Installator commands ---");
43+
Console.Out.WriteLine("help : Displays help pages");
44+
Console.Out.WriteLine("stop : Stops installer");
45+
Console.Out.WriteLine("install : Installs PocketMine server");
46+
Console.Out.WriteLine("start : Starts PocketMine server");
47+
Console.Out.WriteLine("remove : Removes PocketMine server");
48+
Console.Out.WriteLine("list : Displays list of available servers");
49+
break;
50+
case "stop":
51+
Console.Out.WriteLine("Installer stopped!");
52+
Environment.Exit(0);
53+
break;
54+
case "install":
55+
if(argsCount < 2) {
56+
Console.Out.WriteLine("Use 'install <serverName>'");
57+
break;
58+
}
59+
60+
string name = "";
61+
string path = getDataPath() + (name = string.Join(" ", args.Skip(1).ToArray()));
62+
Install(name, path);
63+
break;
64+
case "start":
65+
if (argsCount < 2)
66+
{
67+
Console.Out.WriteLine("Use 'start <serverName>'");
68+
break;
69+
}
70+
71+
Start(args[1]);
72+
break;
73+
case "list":
74+
string[] dirs = System.IO.Directory.GetDirectories(getDataPath(), "*", System.IO.SearchOption.TopDirectoryOnly);
75+
string[] server = { };
76+
foreach(string dir in dirs)
77+
{
78+
System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(dir);
79+
if (info.Name != "bin")
80+
{
81+
server = server.Concat(new string[] { info.Name }).ToArray();
82+
83+
}
84+
}
85+
86+
Console.Out.WriteLine("Available servers: " + string.Join(", ", server));
87+
88+
break;
89+
case "remove":
90+
if (argsCount < 2)
91+
{
92+
Console.Out.WriteLine("Use 'start <serverName>'");
93+
break;
94+
}
95+
96+
Remove(args[1]);
97+
break;
98+
default:
99+
Console.Out.WriteLine("Type 'help' to display PocketMine installer commands.");
100+
break;
101+
}
102+
}
103+
104+
static void Remove(string name)
105+
{
106+
if (!System.IO.Directory.Exists(getDataPath() + name))
107+
{
108+
Console.Out.WriteLine("Server " + name + " was not found!");
109+
return;
110+
}
111+
112+
try
113+
{
114+
System.IO.Directory.Delete(getDataPath() + name, true);
115+
116+
Console.ForegroundColor = ConsoleColor.White;
117+
Console.BackgroundColor = ConsoleColor.DarkGreen;
118+
Console.Out.WriteLine("Server "+name+" removed!");
119+
Console.ForegroundColor = ConsoleColor.Gray;
120+
Console.BackgroundColor = ConsoleColor.Black;
121+
122+
}
123+
catch(Exception e)
124+
{
125+
Console.BackgroundColor = ConsoleColor.Red;
126+
Console.Out.WriteLine(e.Message);
127+
Console.BackgroundColor = ConsoleColor.Black;
128+
}
129+
130+
131+
}
132+
133+
134+
static void Start(string name)
135+
{
136+
if(!System.IO.Directory.Exists(getDataPath() + name))
137+
{
138+
Console.Out.WriteLine("Server " + name + " was not found!");
139+
return;
140+
}
141+
142+
ProcessStartInfo cmd = new ProcessStartInfo();
143+
cmd.FileName = getDataPath() + name + "/start.cmd";
144+
145+
Process process = new Process();
146+
process.StartInfo = cmd;
147+
process.Start();
148+
process.WaitForExit();
149+
150+
Console.ForegroundColor = ConsoleColor.White;
151+
Console.BackgroundColor = ConsoleColor.DarkGreen;
152+
Console.Out.WriteLine("Server '"+ name +"' started!");
153+
Console.ForegroundColor = ConsoleColor.Gray;
154+
Console.BackgroundColor = ConsoleColor.Black;
155+
156+
}
157+
158+
static void Install(string name, string path)
159+
{
160+
if(System.IO.Directory.Exists(path)) {
161+
Console.Out.WriteLine("Server " + name + " is already installed!");
162+
return;
163+
}
164+
165+
InitDirectories();
166+
InstallPhp();
167+
168+
Console.ForegroundColor = ConsoleColor.White;
169+
Console.WriteLine("Installing into directory '" + path + "'");
170+
Console.ForegroundColor = ConsoleColor.Gray;
171+
172+
Console.Out.WriteLine("Creating directory for the server...");
173+
System.IO.Directory.CreateDirectory(path);
174+
175+
Console.Out.WriteLine("Downloading latest PocketMine-MP.phar from github...");
176+
WebClient webClient = new WebClient();
177+
webClient.DownloadFile("https://jenkins.pmmp.io/job/PocketMine-MP/lastSuccessfulBuild/artifact/PocketMine-MP.phar", path + "/PocketMine-MP.phar");
178+
Console.Out.WriteLine("PocketMine-MP downloaded!");
179+
180+
Console.Out.WriteLine("Generating starting script...");
181+
System.IO.File.WriteAllText(path + "/start.cmd", "@echo off\r\n" +
182+
"CD " + path + "/\r\n" +
183+
"TITLE PocketMine-MP server software for Minecraft: Pocket Edition\r\n" +
184+
"REM pause on exitcode != 0 so the user can see what went wrong\r\n" +
185+
getDataPath() + "bin/php/php.exe " + path + "/PocketMine-MP.phar");
186+
187+
Console.ForegroundColor = ConsoleColor.White;
188+
Console.BackgroundColor = ConsoleColor.DarkGreen;
189+
Console.Out.WriteLine("Server " + name + " installed!");
190+
Console.ForegroundColor = ConsoleColor.Gray;
191+
Console.BackgroundColor = ConsoleColor.Black;
192+
}
193+
194+
static void InitDirectories()
195+
{
196+
if (!System.IO.Directory.Exists(getDataPath())) {
197+
System.IO.Directory.CreateDirectory(getDataPath());
198+
Console.Out.WriteLine("Created directory '" + getDataPath() + "'!");
199+
}
200+
}
201+
202+
static void InstallPhp()
203+
{
204+
if(System.IO.Directory.Exists(getDataPath() + "bin")) {
205+
return;
206+
}
207+
208+
Console.ForegroundColor = ConsoleColor.White;
209+
Console.Out.WriteLine("PHP not found, installing php ...");
210+
Console.ForegroundColor = ConsoleColor.Gray;
211+
Console.Out.WriteLine("Downloading php.zip ...");
212+
213+
WebClient webClient = new WebClient();
214+
webClient.DownloadFile(windowsPhpURL, getDataPath() + "php.zip");
215+
Console.Out.WriteLine("PHP downloaded!");
216+
217+
Console.Out.WriteLine("Extracting php...");
218+
ZipFile.ExtractToDirectory(getDataPath() + "php.zip", getDataPath());
219+
Console.Out.WriteLine("PHP extracted!");
220+
221+
Console.Out.WriteLine("Removing unuseful files...");
222+
if(System.IO.File.Exists(getDataPath() + "vc_redist.x64.exe")) {
223+
System.IO.File.Delete(getDataPath() + "vc_redist.x64.exe");
224+
}
225+
if (System.IO.File.Exists(getDataPath() + "vc_redist.x86.exe")) {
226+
System.IO.File.Delete(getDataPath() + "vc_redist.x86.exe");
227+
}
228+
if (System.IO.File.Exists(getDataPath() + "php.zip")) {
229+
System.IO.File.Delete(getDataPath() + "php.zip");
230+
}
231+
232+
Console.ForegroundColor = ConsoleColor.White;
233+
Console.BackgroundColor = ConsoleColor.DarkGreen;
234+
Console.Out.WriteLine("PocketMine php installed!");
235+
Console.ForegroundColor = ConsoleColor.Gray;
236+
Console.BackgroundColor = ConsoleColor.Black;
237+
}
238+
239+
static string getDataPath()
240+
{
241+
return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/PocketMine/";
242+
}
243+
}
244+
}

0 commit comments

Comments
 (0)