diff --git a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp index 7909351db..9a0130925 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp +++ b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp @@ -2381,19 +2381,7 @@ void PythonContext::LaunchDebugger(QWidget *window, PersistentConfig &config, QS return; if(context_location.isEmpty()) - { - for(QString path : QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)) - { - QDir tmpDir(path); - tmpDir.mkpath(lit("pytmp")); - tmpDir.cd(lit("pytmp")); - if(tmpDir.exists()) - { - context_location = tmpDir.absolutePath(); - break; - } - } - } + return; // don't overwrite an existing file, to allow user customisation QDir context_dir(context_location); diff --git a/qrenderdoc/Windows/PythonShell.cpp b/qrenderdoc/Windows/PythonShell.cpp index 502880dfa..da8105486 100644 --- a/qrenderdoc/Windows/PythonShell.cpp +++ b/qrenderdoc/Windows/PythonShell.cpp @@ -1247,6 +1247,22 @@ void PythonShell::runScript(bool debugging) if(debugging) PythonContext::PrepareDebuggerWait(); + // save any changes + if(editor->isModified() && !editor->filename().isEmpty()) + { + saveEditor(editor, editor->filename()); + } + else if(editor->filename().isEmpty()) + { + // write the script as a temporary file, so if we crash it will be recoverable. + // this only applies if editor is an unsaved file + QString unsavedFile = context->GetTempFilename(lit("script.py")); + QFile f(unsavedFile); + f.open(QFile::Truncate | QFile::WriteOnly); + f.write(script.toUtf8().data()); + f.close(); + } + m_CurLineTimer->start(); LambdaThread *thread = new LambdaThread([this, debugging, script, context, editor]() { @@ -1254,7 +1270,7 @@ void PythonShell::runScript(bool debugging) scriptContext = context; runningScriptEditor = editor->scintilla(); - context->executeString(lit("script.py"), script, debugging); + context->executeString(editor->filename(), script, debugging); scriptContext = NULL; GUIInvoke::call(this, [this, context]() { @@ -1263,6 +1279,9 @@ void PythonShell::runScript(bool debugging) context->Finish(); runningScriptEditor = NULL; enableButtons(true); + + QString unsavedFile = context->GetTempFilename(lit("script.py")); + QFile::remove(unsavedFile); }); PythonContext::RemoveDebuggableThread();