<commit_before>#include "stdafx.h"
#include "CtrlrMacros.h"
#include "CtrlrLog.h"
#include "CtrlrStandaloneWindow.h"

class CtrlrApplication : public JUCEApplication
{
        public:
                CtrlrApplication() : filterWindow(nullptr)
                {
                }

				static void crashHandler()
				{
					if (JUCEApplication::isStandaloneApp())
					{
						MemoryBlock mb (SystemStats::getStackBacktrace().toUTF8(), SystemStats::getStackBacktrace().length());
						File::getSpecialLocation(File::currentApplicationFile)
							.startAsProcess("--crashReport=\""
											+File::getSpecialLocation(File::currentApplicationFile).getFullPathName()
											+"\" --stackTrace=\""+mb.toBase64Encoding()
											+"\"");
					}
					else
					{
						const String stackTrace = SystemStats::getStackBacktrace();
						File crashFile (File::getSpecialLocation(File::currentApplicationFile).getFileExtension()+".crash");

						AlertWindow::showMessageBox (AlertWindow::WarningIcon,
														"Ctrlr has crashed",
														"Looks like Ctrlr has crashed, since this is not a standalone instance, we won't do anything.\
														A crash log will be written to "+crashFile.getFullPathName()
														+"\n\n"+stackTrace);

						crashFile.replaceWithText ("Ctrlr crash at: "+Time::getCurrentTime().toString(true, true, true, true) + "\nStack trace:\n"+stackTrace);
					}
				}

				const StringArray getParameters(const String &cli)
				{
					StringArray tokens;
					StringArray ret;
					tokens.addTokens (cli, " ", "\'\"");

					for (int i=0; i<tokens.size(); i++)
					{
						ret.add (tokens[i].fromFirstOccurrenceOf ("--", false, false).upToFirstOccurrenceOf("=", false, true));
					}

					return (ret);
				}

				const StringArray getParameterValues(const String &cli)
				{
					StringArray tokens;
					StringArray ret;
					tokens.addTokens (cli, " ", "\'\"");

					for (int i=0; i<tokens.size(); i++)
					{
						ret.add (tokens[i].fromFirstOccurrenceOf ("=", false, false).unquoted().trim());
					}

					return (ret);
				}

                void initialise(const String& commandLineParameters)
                {
					Logger::writeToLog("CTRLR:initialise params \""+commandLineParameters+"\"");

					SystemStats::setApplicationCrashHandler ((juce::SystemStats::CrashHandlerFunction) &CtrlrApplication::crashHandler);

					if (!commandLineParameters.isEmpty())
					{
						String stackTrace = "?";
						StringArray parameters		= getParameters(commandLineParameters);
						StringArray parameterValues	= getParameterValues(commandLineParameters);

						if (parameters.contains("crashReport"))
						{
							File crashReportForExec(parameterValues[parameters.indexOf("crashReport")]);
							File crashReportFile(crashReportForExec.withFileExtension(crashReportForExec.getFileExtension()+".crash"));
							AlertWindow crashReport("Ctrlr has crashed", "This is a crash indicator, it means that Ctrlr has crashed for some reason. Some crash information will be written to: "+crashReportFile.getFullPathName(), AlertWindow::WarningIcon);

							if (parameters.contains("stackTrace"))
							{
								if (!parameterValues[parameters.indexOf("stackTrace")].isEmpty())
								{
									MemoryBlock mb;
									mb.fromBase64Encoding(parameterValues[parameters.indexOf("stackTrace")]);
									stackTrace = mb.toString();
									crashReport.addTextBlock (stackTrace);
								}
							}
							crashReport.addButton ("OK", 1, KeyPress (KeyPress::returnKey));
							crashReport.runModalLoop();

							crashReportFile.replaceWithText ("Ctrlr crash at: "+Time::getCurrentTime().toString(true, true, true, true) + "\nStack trace:\n"+stackTrace);

							JUCEApplication::quit();
						}
					}


					filterWindow = new CtrlrStandaloneWindow (ProjectInfo::projectName + String("/") + ProjectInfo::versionString, Colours::lightgrey);

					if (File::isAbsolutePath(commandLineParameters.unquoted()))
						filterWindow->openFileFromCli (File(commandLineParameters.unquoted()));
                }

                void shutdown()
                {
					if (filterWindow)<commit_msg>Don't set the crash handler when we are the crash handler.<commit_after>#include "stdafx.h"
#include "CtrlrMacros.h"
#include "CtrlrLog.h"
#include "CtrlrStandaloneWindow.h"

class CtrlrApplication : public JUCEApplication
{
        public:
                CtrlrApplication() : filterWindow(nullptr)
                {
                }

				static void crashHandler()
				{
					if (JUCEApplication::isStandaloneApp())
					{
						MemoryBlock mb (SystemStats::getStackBacktrace().toUTF8(), SystemStats::getStackBacktrace().length());
						File::getSpecialLocation(File::currentApplicationFile)
							.startAsProcess("--crashReport=\""
											+File::getSpecialLocation(File::currentApplicationFile).getFullPathName()
											+"\" --stackTrace=\""+mb.toBase64Encoding()
											+"\"");
					}
					else
					{
						const String stackTrace = SystemStats::getStackBacktrace();
						File crashFile (File::getSpecialLocation(File::currentApplicationFile).getFileExtension()+".crash");

						AlertWindow::showMessageBox (AlertWindow::WarningIcon,
														"Ctrlr has crashed",
														"Looks like Ctrlr has crashed, since this is not a standalone instance, we won't do anything.\
														A crash log will be written to "+crashFile.getFullPathName()
														+"\n\n"+stackTrace);

						crashFile.replaceWithText ("Ctrlr crash at: "+Time::getCurrentTime().toString(true, true, true, true) + "\nStack trace:\n"+stackTrace);
					}
				}

				const StringArray getParameters(const String &cli)
				{
					StringArray tokens;
					StringArray ret;
					tokens.addTokens (cli, " ", "\'\"");

					for (int i=0; i<tokens.size(); i++)
					{
						ret.add (tokens[i].fromFirstOccurrenceOf ("--", false, false).upToFirstOccurrenceOf("=", false, true));
					}

					return (ret);
				}

				const StringArray getParameterValues(const String &cli)
				{
					StringArray tokens;
					StringArray ret;
					tokens.addTokens (cli, " ", "\'\"");

					for (int i=0; i<tokens.size(); i++)
					{
						ret.add (tokens[i].fromFirstOccurrenceOf ("=", false, false).unquoted().trim());
					}

					return (ret);
				}

                void initialise(const String& commandLineParameters)
                {
					Logger::writeToLog("CTRLR:initialise params \""+commandLineParameters+"\"");


					{
						bool setcrashhandler = true;
						if (!commandLineParameters.isEmpty())
						{
							String stackTrace = "?";
							StringArray parameters		= getParameters(commandLineParameters);
							StringArray parameterValues	= getParameterValues(commandLineParameters);

							if (parameters.contains("crashReport"))
							{
								File crashReportForExec(parameterValues[parameters.indexOf("crashReport")]);
								File crashReportFile(crashReportForExec.withFileExtension(crashReportForExec.getFileExtension()+".crash"));
								AlertWindow crashReport("Ctrlr has crashed", "This is a crash indicator, it means that Ctrlr has crashed for some reason. Some crash information will be written to: "+crashReportFile.getFullPathName(), AlertWindow::WarningIcon);

								if (parameters.contains("stackTrace"))
								{
									if (!parameterValues[parameters.indexOf("stackTrace")].isEmpty())
									{
										MemoryBlock mb;
										mb.fromBase64Encoding(parameterValues[parameters.indexOf("stackTrace")]);
										stackTrace = mb.toString();
										crashReport.addTextBlock (stackTrace);
									}
								}
								crashReport.addButton ("OK", 1, KeyPress (KeyPress::returnKey));
								crashReport.runModalLoop();

								crashReportFile.replaceWithText ("Ctrlr crash at: "+Time::getCurrentTime().toString(true, true, true, true) + "\nStack trace:\n"+stackTrace);

								JUCEApplication::quit();
							}
						}
						// Set the crash handler only, if no crash is reported.
						if (setcrashhandler)
							SystemStats::setApplicationCrashHandler ((juce::SystemStats::CrashHandlerFunction) &CtrlrApplication::crashHandler);
					}


					filterWindow = new CtrlrStandaloneWindow (ProjectInfo::projectName + String("/") + ProjectInfo::versionString, Colours::lightgrey);

					if (File::isAbsolutePath(commandLineParameters.unquoted()))
						filterWindow->openFileFromCli (File(commandLineParameters.unquoted()));
                }

                void shutdown()
                {
					if (filterWindow)
{'fraction_non_alphanumeric': 0.12831701851633448, 'fraction_numerical': 0.0018870149781813894, 'mean_word_length': 3.0966183574879227, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5934349', 'n_tokens_mistral': 3254, 'n_tokens_neox': 2327, 'n_words': 460}