Skip to content

Commit

Permalink
Fixed bug where rendering would cancel or application would suddenly …
Browse files Browse the repository at this point in the history
…close
  • Loading branch information
clvrk committed May 25, 2020
1 parent 2d9198b commit 2c5a3e8
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 43 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ services:
- docker
env:
global:
- REPO_NAME=$(echo $TRAVIS_BUILD_DIR | sed -r 's/^.+\///g')
- TAG_CLEAN="$(if [ -z $TRAVIS_TAG ]; then echo '1.0.0'; else echo $(echo $TRAVIS_TAG | sed -r 's/^v//g'); fi)"
- ASSEMBLY_VERSION=$(echo $TAG_CLEAN | sed -r 's/^.+\./&'$TRAVIS_BUILD_NUMBER'./g')
- SRC_MOUNT=/usr/local/src/${REPO_NAME}
jobs:
- RUNTIME=win-x64
before_install:
- cd ~/build/clarkx86 && git clone https://github.com/clarkx86/common_ci-scripts.git && cd common_ci-scripts && chmod +x ./*
- REPO_NAME=$(./get_repo-name.sh $TRAVIS_REPO_SLUG)
- TAG_CLEAN=$(./get_tag_clean.sh $TRAVIS_TAG)
- ASSEMBLY_VERSION=$(./format_assembly-version.sh $TAG_CLEAN $TRAVIS_BUILD_NUMBER)
- ARTIFACT_NAME=${REPO_NAME}_${RUNTIME}_v${TAG_CLEAN}-${TRAVIS_BUILD_NUMBER}
- sed -r -i 's/[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+/'$ASSEMBLY_VERSION'/'
Properties/AssemblyInfo.cs
- ./patch_assemblyinfo-version.sh ~/build/${TRAVIS_REPO_SLUG}/Properties/AssemblyInfo.cs $ASSEMBLY_VERSION
- cd ~/build/${TRAVIS_REPO_SLUG}
install:
- docker run --name mono_build -t -d -v ~/build/${TRAVIS_REPO_SLUG}:${SRC_MOUNT} -w $SRC_MOUNT mono
- docker exec mono_build nuget restore
script:
Expand Down
62 changes: 31 additions & 31 deletions AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ public class AppSettings
public AppSettings()
{
// Global config
this.config["checkForUpdatesOnStartup"] = false;
this.config["variant"] = 0;
this.config["world"] = @"C:/Users/%username%/AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/minecraftWorlds/";
this.config["output"] = "";
config["checkForUpdatesOnStartup"] = false;
config["variant"] = 0;
config["world"] = @"C:/Users/%username%/AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/minecraftWorlds/";
config["output"] = "";

// papyrus.cs config
this.config_cs["executable"] = "";
this.config_cs["limitXZ_enable"] = false;
this.config_cs["limitXZ_X1"] = 0;
this.config_cs["limitXZ_X2"] = 0;
this.config_cs["limitXZ_Z1"] = 0;
this.config_cs["limitXZ_Z2"] = 0;
this.config_cs["ingame_coords"] = true;
this.config_cs["limitY_enable"] = false;
this.config_cs["limitY"] = 64;
this.config_cs["heightmap_enable"] = true;
this.config_cs["heightmap_j"] = 10000;
this.config_cs["heightmap_divider"] = 20;
this.config_cs["heightmap_offset"] = 64;
this.config_cs["dimension"] = 0;
this.config_cs["profile"] = "Default";
this.config_cs["html_filename"] = "index.html";
this.config_cs["image_format"] = "PNG";
this.config_cs["image_quality"] = 100;
this.config_cs["force_overwrite"] = false;
this.config_cs["leaflet"] = false;
config_cs["executable"] = "";
config_cs["limitXZ_enable"] = false;
config_cs["limitXZ_X1"] = 0;
config_cs["limitXZ_X2"] = 0;
config_cs["limitXZ_Z1"] = 0;
config_cs["limitXZ_Z2"] = 0;
config_cs["ingame_coords"] = true;
config_cs["limitY_enable"] = false;
config_cs["limitY"] = 64;
config_cs["heightmap_enable"] = true;
config_cs["heightmap_j"] = 10000;
config_cs["heightmap_divider"] = 20;
config_cs["heightmap_offset"] = 64;
config_cs["dimension"] = 0;
config_cs["profile"] = "Default";
config_cs["html_filename"] = "index.html";
config_cs["image_format"] = "PNG";
config_cs["image_quality"] = 100;
config_cs["force_overwrite"] = false;
config_cs["leaflet"] = false;
}

public string GetArguments(PapyrusVariant variant, bool includeExePath, string worldPath, string outputPath)
Expand All @@ -49,23 +49,23 @@ public string GetArguments(PapyrusVariant variant, bool includeExePath, string w
case PapyrusVariant.PAPYRUSCS:
if (includeExePath)
{
exePath = String.Format("\"{0}\" ", System.IO.Path.GetFullPath(this.config_cs["executable"]));
exePath = String.Format("\"{0}\" ", System.IO.Path.GetFullPath(config_cs["executable"]));
}

String[] additionalArgs = new String[2];

if (this.config_cs["profile"].ToLower() != "default")
if (config_cs["profile"].ToLower() != "default")
{
additionalArgs[0] = String.Format("--profile {0}", this.config_cs["profile"].ToLower());
additionalArgs[0] = String.Format("--profile {0}", config_cs["profile"].ToLower());
}

if (this.config_cs["limitXZ_enable"])
if (config_cs["limitXZ_enable"])
{
int divider = this.config_cs["ingame_coords"] ? 16 : 1;
additionalArgs[1] = String.Format("--limitx {0},{1} --limitz {2},{3}", this.config_cs["limitXZ_X1"] / divider, this.config_cs["limitXZ_X2"] / divider, this.config_cs["limitXZ_Z1"] / divider, this.config_cs["limitXZ_Z2"] / divider);
int divider = config_cs["ingame_coords"] ? 16 : 1;
additionalArgs[1] = String.Format("--limitx {0},{1} --limitz {2},{3}", config_cs["limitXZ_X1"] / divider, config_cs["limitXZ_X2"] / divider, config_cs["limitXZ_Z1"] / divider, config_cs["limitXZ_Z2"] / divider);
}

arguments = String.Format(exePath + "-w \"{0}\" -o \"{1}\" --dim {2} -f {3} {4} --brillouin_j {5} --brillouin_divider {6} --brillouin_offset {7} --forceoverwrite {8} --use_leaflet_legacy {9} --htmlfile {10} {11} {12}", worldPath, outputPath, this.config_cs["dimension"], this.config_cs["image_format"].ToString().ToLower(), this.config_cs["image_quality"], this.config_cs["heightmap_j"], this.config_cs["heightmap_divider"], this.config_cs["heightmap_offset"], Convert.ToString(this.config_cs["force_overwrite"]).ToLower(), Convert.ToString(this.config_cs["leaflet"]).ToLower(), this.config_cs["html_filename"], additionalArgs[0], additionalArgs[1]);
arguments = String.Format(exePath + "-w \"{0}\" -o \"{1}\" --dim {2} -f {3} {4} --brillouin_j {5} --brillouin_divider {6} --brillouin_offset {7} --forceoverwrite {8} --use_leaflet_legacy {9} --htmlfile {10} {11} {12}", worldPath, outputPath, config_cs["dimension"], config_cs["image_format"].ToString().ToLower(), config_cs["image_quality"], config_cs["heightmap_j"], config_cs["heightmap_divider"], config_cs["heightmap_offset"], Convert.ToString(config_cs["force_overwrite"]).ToLower(), Convert.ToString(config_cs["leaflet"]).ToLower(), config_cs["html_filename"], additionalArgs[0], additionalArgs[1]);

break;

Expand Down
1 change: 1 addition & 0 deletions Forms/FormConfigure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public FormConfigure(FormMain formMain)
numericUpDownXzX2.Value = (int)FormMain.Settings.config_cs["limitXZ_X2"];
numericUpDownXzZ1.Value = (int)FormMain.Settings.config_cs["limitXZ_Z1"];
numericUpDownXzZ2.Value = (int)FormMain.Settings.config_cs["limitXZ_Z2"];
checkBoxIngameCoordinates.Checked = (bool)FormMain.Settings.config_cs["ingame_coords"];
checkBoxLimitY.Checked = Convert.ToBoolean(FormMain.Settings.config_cs["limitY_enable"]);
numericUpDownLimitY.Value = (int)FormMain.Settings.config_cs["limitY"];
checkBoxHeightmap.Checked = Convert.ToBoolean(FormMain.Settings.config_cs["heightmap_enable"]);
Expand Down
42 changes: 35 additions & 7 deletions Forms/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Timers;
using System.Net;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;

namespace papyrus_gui
{
Expand All @@ -32,13 +33,27 @@ public partial class FormMain : Form
public UpdateHandler UHandler;
public ProcessExitedHandler ProcessExitHandler;
public FormConfigure formConfigure;
public static AppSettings Settings;
public AppSettings Settings;
public static string AppVersion = String.Format("{0}.{1}.{2}", Assembly.GetExecutingAssembly().GetName().Version.Major, Assembly.GetExecutingAssembly().GetName().Version.Minor, Assembly.GetExecutingAssembly().GetName().Version.Revision);
private LogContent _logContent;
private ProcessingStatus _status = ProcessingStatus.IDLE;
public Process _renderProcess;
private uint _uiRefreshTickingRate = 500;

[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr handle, uint msg, IntPtr wParam, IntPtr lParam);

private enum WindowMessage
{
WM_VSCROLL = 0x0115
}

private enum ScrollbarMessage
{
SB_PAGEDOWN = 0x03,
SB_BOTTOM = 0x07
}

public FormMain()
{
InitializeComponent();
Expand Down Expand Up @@ -129,6 +144,19 @@ public FormMain()
checkForUpdateTimer.Start();

formConfigure = new FormConfigure(this);

/*
// Write unhandled exceptions to timestamped crashlog-file
AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs eArgs) =>
{
string fName = String.Format("./{0}_crashlog.txt", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
using (StreamWriter crashLogWriter = new StreamWriter(Path.GetFullPath(fName)))
{
Exception e = ((Exception)eArgs.ExceptionObject);
crashLogWriter.Write(e.Message);
}
};
*/
}

public void UpdateCheck(bool notifyLatest)
Expand Down Expand Up @@ -191,7 +219,7 @@ private void CloseApplication(object sender, FormClosingEventArgs e)
Settings.config["world"] = textBoxWorld.Text;
Settings.config["output"] = textBoxOutput.Text;

using (StreamWriter streamWriter = new StreamWriter(@".\configuration.json", false))
using (StreamWriter streamWriter = new StreamWriter("configuration.json", false))
{
streamWriter.Write(JsonConvert.SerializeObject(Settings, Formatting.Indented));
}
Expand Down Expand Up @@ -226,10 +254,10 @@ public void UpdateConsole(string stdOut)
if (checkBoxEnableConsoleOutput.Checked)
{
_logContent.Append(stdOut);
richTextBoxConsoleOutput.Clear();
// richTextBoxConsoleOutput.Clear();
richTextBoxConsoleOutput.Lines = _logContent.Lines;
richTextBoxConsoleOutput.SelectionStart = richTextBoxConsoleOutput.TextLength;
richTextBoxConsoleOutput.ScrollToCaret();
// richTextBoxConsoleOutput.SelectionStart = richTextBoxConsoleOutput.TextLength;
SendMessage(richTextBoxConsoleOutput.Handle, (uint)WindowMessage.WM_VSCROLL, (IntPtr)ScrollbarMessage.SB_BOTTOM, IntPtr.Zero);
}
}

Expand All @@ -256,8 +284,8 @@ private void ButtonRender_Click(object sender, EventArgs e)
Thread renderThread = new Thread(new ThreadStart(() =>
{
_renderProcess = new Process();
_renderProcess.StartInfo.FileName = FormMain.Settings.config_cs["executable"];
_renderProcess.StartInfo.Arguments = FormMain.Settings.GetArguments(PapyrusVariant.PAPYRUSCS, false, Path.GetFullPath(textBoxWorld.Text.ToString()), Path.GetFullPath(textBoxOutput.Text.ToString()));
_renderProcess.StartInfo.FileName = Settings.config_cs["executable"];
_renderProcess.StartInfo.Arguments = Settings.GetArguments(PapyrusVariant.PAPYRUSCS, false, Path.GetFullPath(textBoxWorld.Text.ToString()), Path.GetFullPath(textBoxOutput.Text.ToString()));
_renderProcess.StartInfo.UseShellExecute = false;
_renderProcess.StartInfo.RedirectStandardOutput = true;
_renderProcess.StartInfo.CreateNoWindow = true;
Expand Down

0 comments on commit 2c5a3e8

Please sign in to comment.