Skip to content
This repository was archived by the owner on Aug 3, 2023. It is now read-only.

Commit c97ce88

Browse files
committed
Fixed release not working
Made possible to open .json file with this
1 parent 54ed479 commit c97ce88

File tree

13 files changed

+389
-42
lines changed

13 files changed

+389
-42
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
bin/
33
obj/
44
Properties/
5-
BuildPlate_Editor.sln
5+
BuildPlate_Editor.sln
6+
1051469223874011206.ico

BuildPlate_Editor.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
<ErrorReport>prompt</ErrorReport>
5353
<Prefer32Bit>true</Prefer32Bit>
5454
</PropertyGroup>
55+
<PropertyGroup>
56+
<ApplicationIcon>1051469223874011206.ico</ApplicationIcon>
57+
</PropertyGroup>
5558
<ItemGroup>
5659
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
5760
<HintPath>packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
@@ -62,6 +65,7 @@
6265
<Reference Include="System" />
6366
<Reference Include="System.Core" />
6467
<Reference Include="System.Drawing" />
68+
<Reference Include="System.Web" />
6569
<Reference Include="System.Windows.Forms" />
6670
<Reference Include="System.Xml.Linq" />
6771
<Reference Include="System.Data.DataSetExtensions" />
@@ -113,6 +117,7 @@
113117
<None Include="packages.config" />
114118
</ItemGroup>
115119
<ItemGroup>
120+
<Content Include="1051469223874011206.ico" />
116121
<Content Include="Data\Textures\Black.png">
117122
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
118123
</Content>

Data/Shaders/shader.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 460 core
1+
#version 450 core
22

33
out vec4 FragColor;
44

Data/Shaders/shader.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 460 core
1+
#version 450 core
22
layout (location = 0) in vec3 aPosition;
33
layout (location = 1) in vec3 aUv;
44

Data/Shaders/ui.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 460 core
1+
#version 450 core
22

33
out vec4 FragColor;
44

Data/Shaders/ui.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 460 core
1+
#version 450 core
22

33
layout (location = 0) in vec3 aPosition;
44

Program.cs

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
using System;
1+
using Microsoft.Win32;
2+
using System;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.IO;
56
using System.Linq;
7+
using System.Reflection;
8+
using System.Runtime.ExceptionServices;
69
using System.Text;
710
using System.Threading.Tasks;
811
using SystemPlus;
@@ -12,16 +15,67 @@ namespace BuildPlate_Editor
1215
class Program
1316
{
1417
public static Window Window;
18+
public static string baseDir;
1519

20+
// todo: check json is buildplate
1621
static void Main(string[] args)
1722
{
18-
if (!File.Exists(Environment.CurrentDirectory + "/texturesPath.txt")) {
23+
// Get base path (.exe location)
24+
string myExecutable = Assembly.GetEntryAssembly().Location;
25+
26+
if (args != null && args.Length > 0 && args[0] == "setJsonDefault") {
27+
Util.SetAssociationWithExtension(".json", "Json", myExecutable, "BuildPlate");
28+
Console.WriteLine("Set .json as default, To Apply: Select .json file, click \"Open with\", \"Choose another app\", " +
29+
"Select BuildPlate_Editor, Check \"Always use this app...\"");
30+
Console.WriteLine("Press any key to continue...");
31+
Console.ReadKey(true);
32+
return;
33+
}
34+
35+
baseDir = Path.GetDirectoryName(myExecutable) + "\\";
36+
Console.WriteLine($"Base directory: {baseDir}");
37+
38+
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
39+
40+
if (File.Exists(baseDir + "askedForDefault") || args != null && args.Length > 0)
41+
goto skipAks;
42+
43+
Console.Write("Would you like to set this as default for .json files? (Y/N):");
44+
char typed = Console.ReadKey().KeyChar;
45+
Console.WriteLine();
46+
if (typed == 'y' || typed == 'Y') {
47+
// Make this app default for .json files
48+
try {
49+
// Launch again with admin, so it can edit registry
50+
using (Process configTool = new Process()) {
51+
configTool.StartInfo.FileName = myExecutable;
52+
configTool.StartInfo.Arguments = "setJsonDefault";
53+
configTool.StartInfo.Verb = "runas";
54+
configTool.Start();
55+
configTool.WaitForExit();
56+
}
57+
Console.WriteLine("Set this as default for .json");
58+
} catch (Exception ex) {
59+
Console.WriteLine($"Failed to edit registry: {ex}");
60+
Console.WriteLine("Press any key to continue...");
61+
Console.ReadKey(true);
62+
goto skipAks;
63+
}
64+
}
65+
else
66+
Console.WriteLine("Ok :(, I won't aks again");
67+
68+
File.WriteAllBytes(baseDir + "askedForDefault", new byte[0]);
69+
70+
skipAks:
71+
72+
if (!File.Exists(baseDir + "texturesPath.txt")) {
1973
Console.WriteLine("texturesPath.txt doen't exist");
2074
Console.WriteLine($"Extract mce resource pack 2 times and set path to {{path}}/textures/blocks/");
2175
Console.ReadKey(true);
2276
return;
2377
}
24-
string texturesPath = File.ReadAllText(Environment.CurrentDirectory + "/texturesPath.txt");
78+
string texturesPath = File.ReadAllText(baseDir + "texturesPath.txt");
2579
if (texturesPath == string.Empty || !Directory.Exists(texturesPath)) {
2680
Console.WriteLine($"path inside texturesPath.txt ({texturesPath}) doesn't exist");
2781
Console.WriteLine($"Extract mce resource pack 2 times and set path to {{path}}/textures/blocks/");
@@ -33,16 +87,23 @@ static void Main(string[] args)
3387
texturesPath += '/';
3488
World.textureBasePath = texturesPath;
3589
#if DEBUG
36-
World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\b22b4ada-49e5-41c9-8bf0-76e36c5ec7b2.json";
90+
//World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\7cd6d53b-1715-4b22-9a99-d6d43edd61df.json";
91+
World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\00d1fa99-7acf-449d-bb4f-8d11127bd6e3.json";
3792
#else
3893
Console.Write("Build plate to edit (.json): ");
39-
string buildPlate = Console.ReadLine();
40-
if (!File.Exists(buildPlate)) {
41-
Console.WriteLine($"build plate \"{buildPlate}\" doesn't exist");
42-
Console.ReadKey(true);
43-
return;
94+
if (args != null && args.Length > 0 && File.Exists(args[0])) {
95+
World.targetFilePath = args[0];
96+
Console.WriteLine(args[0]);
97+
}
98+
else {
99+
string buildPlate = Console.ReadLine();
100+
if (!File.Exists(buildPlate)) {
101+
Console.WriteLine($"build plate \"{buildPlate}\" doesn't exist");
102+
Console.ReadKey(true);
103+
return;
104+
}
105+
World.targetFilePath = buildPlate;
44106
}
45-
World.targetFilePath = buildPlate;
46107
#endif
47108
Window = new Window();
48109
string version;
@@ -56,6 +117,16 @@ static void Main(string[] args)
56117
Window.Run(60d);
57118
}
58119

120+
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
121+
{
122+
Exception ex = (Exception)e.ExceptionObject;
123+
Console.WriteLine($"CurrentDomain_UnhandledException: {ex.Message}");
124+
Console.WriteLine($"Source: {ex.Source}");
125+
Console.WriteLine($"Stack trace: {ex.StackTrace}");
126+
Console.WriteLine("Press any key to exit...");
127+
Console.ReadKey(true);
128+
}
129+
59130
private static void LowVersion()
60131
{
61132
Console.WriteLine("OpenGL version is low. The editor might not work correctly");

Shader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class Shader
2020

2121
public void Compile(string shaderName)
2222
{
23-
string path = Environment.CurrentDirectory + "/Data/Shaders/" + shaderName;
23+
string path = Program.baseDir + "Data/Shaders/" + shaderName;
2424
vertexShaderSource = File.ReadAllText(path + ".vert");
2525
fragmentShaderSource = File.ReadAllText(path + ".frag");
2626

Texture.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static int CreateTextureArray(string[] texturesToLoad, TexFlip flip)
2424
{
2525
int taid;
2626
GL.ActiveTexture(TextureUnit.Texture1);
27-
GL.GenTextures(1, out taid);
27+
taid = GL.GenTexture();
2828
GL.BindTexture(TextureTarget.Texture2DArray, taid);
2929

3030
GL.GenerateMipmap(GenerateMipmapTarget.Texture2DArray);
@@ -42,13 +42,14 @@ public static int CreateTextureArray(string[] texturesToLoad, TexFlip flip)
4242
Console.WriteLine("TEXTURE:BLOCKARRAY:GENERATE:START");
4343
for (int i = 0; i < texturesToLoad.Length; i++) {
4444
string texPath = texturesToLoad[i];
45+
4546
if (!File.Exists(texPath)) {
4647
Console.ForegroundColor = ConsoleColor.Red;
4748
string name = Path.GetFileNameWithoutExtension(texPath);
4849
if (name != "air" && !name.Contains("constraint"))
4950
Console.WriteLine($"Block texture {Path.GetFileName(texPath)}, wasn't found");
5051
Console.ResetColor();
51-
texPath = Environment.CurrentDirectory + "\\Data\\Textures\\Black.png";
52+
texPath = Program.baseDir + "Data\\Textures\\Black.png";
5253
}
5354

5455
bm = new Bitmap(texPath);

Util.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using BuildPlate_Editor.Maths;
2+
using Microsoft.Win32;
23
using Newtonsoft.Json;
34
using OpenTK;
45
using System;
56
using System.Collections.Generic;
67
using System.IO;
78
using System.Linq;
9+
using System.Security.Permissions;
810
using System.Text;
911
using System.Threading.Tasks;
1012

@@ -96,6 +98,24 @@ public static void CubeTex(int _tex, Vector3 pos, Vector3 size, ref List<Vertex>
9698
}
9799
}
98100

101+
public static void CubeTex(int _tex, Vector3 pos, Vector3 size, ref List<Vertex> verts, ref List<uint> tris, Vector2[] uvs)
102+
{
103+
uint tex = (uint)_tex;
104+
for (int p = 0; p < 6; p++) {
105+
uint firstVertIndex = (uint)verts.Count;
106+
verts.Add(new Vertex(pos + VoxelData.voxelVerts[VoxelData.voxelTris[p, 0]] * size - size / 2f, uvs[0], tex));
107+
verts.Add(new Vertex(pos + VoxelData.voxelVerts[VoxelData.voxelTris[p, 1]] * size - size / 2f, uvs[1], tex));
108+
verts.Add(new Vertex(pos + VoxelData.voxelVerts[VoxelData.voxelTris[p, 2]] * size - size / 2f, uvs[2], tex));
109+
verts.Add(new Vertex(pos + VoxelData.voxelVerts[VoxelData.voxelTris[p, 3]] * size - size / 2f, uvs[3], tex));
110+
tris.Add(firstVertIndex);
111+
tris.Add(firstVertIndex + 1);
112+
tris.Add(firstVertIndex + 2);
113+
tris.Add(firstVertIndex + 2);
114+
tris.Add(firstVertIndex + 1);
115+
tris.Add(firstVertIndex + 3);
116+
}
117+
}
118+
99119
public static T2[] ForArray<T1, T2>(this IEnumerator<T1> e, Func<T1, T2> func)
100120
{
101121
List<T2> list = new List<T2>();
@@ -119,5 +139,32 @@ public static T[] Cloned<T>(this T[] array)
119139
Array.Copy(array, newArray, array.Length);
120140
return newArray;
121141
}
142+
143+
public static Vector2 Swaped(this Vector2 v) => new Vector2(v.Y, v.X);
144+
145+
// needs admin
146+
public static void SetAssociationWithExtension(string Extension, string key, string OpenWith, string FileDescription)
147+
{
148+
/*Key: HKLM\SOFTWARE\Classes\.foo
149+
Value: <default> = “Foo.Document”
150+
151+
Key: HKLM\SOFTWARE\Classes\Foo.Document
152+
Value: <default> = “Foo Document”
153+
154+
Key: HKLM\SOFTWARE\Classes\Foo.Document\shell\open\command
155+
Value: <default> = “[blah.exe]” “%1″*/
156+
RegistryKey key1 = Registry.LocalMachine.CreateSubKey($@"SOFTWARE\Classes\{Extension}");
157+
key1.SetValue("", $"{Extension.Replace(".", "")}.Document");
158+
key1.Flush();
159+
RegistryKey key2 = Registry.LocalMachine.CreateSubKey($@"SOFTWARE\Classes\{key}.Document");
160+
key2.SetValue("", FileDescription);
161+
key2.Flush();
162+
RegistryKey key3 = Registry.LocalMachine.CreateSubKey($@"SOFTWARE\Classes\{key}.Document\Shell\Open\Command");
163+
key3.SetValue("", $"{OpenWith} %1");
164+
key3.Flush();
165+
RegistryKey key4 = Registry.LocalMachine.CreateSubKey($@"SOFTWARE\Classes\{key}.Document\Shell\Edit\Command");
166+
key4.SetValue("", $"{OpenWith} %1");
167+
key4.Flush();
168+
}
122169
}
123170
}

0 commit comments

Comments
 (0)