Make SIGINT a bit cleaner for packaging

This commit is contained in:
Jack Andersen 2018-05-25 17:07:04 -10:00
parent ec58e5b35f
commit c11557bcff
8 changed files with 28 additions and 11 deletions

View File

@ -100,9 +100,10 @@ public:
hecl::VerbosityLevel = info.verbosityLevel;
hecl::GuiMode = info.gui;
}
virtual ~ToolBase() {}
virtual ~ToolBase() = default;
virtual hecl::SystemString toolName() const=0;
virtual int run()=0;
virtual void cancel() {}
inline operator bool() const {return m_good;}
};

View File

@ -174,6 +174,11 @@ public:
cp.waitUntilComplete();
return 0;
}
void cancel()
{
m_useProj->interruptCook();
}
};
#endif // CTOOL_COOK

View File

@ -151,7 +151,7 @@ public:
hecl::Printf(_S("" RED BOLD "NOTHING TO EXTRACT" NORMAL "\n"));
else
hecl::Printf(_S("NOTHING TO EXTRACT\n"));
return -1;
return 1;
}
if (XTERM_COLOR)

View File

@ -46,11 +46,11 @@ public:
int run()
{
if (!m_dir)
return -1;
return 1;
size_t ErrorRef = logvisor::ErrorCount;
hecl::Database::Project proj((hecl::ProjectRootPath(*m_dir)));
if (logvisor::ErrorCount > ErrorRef)
return -1;
return 1;
LogModule.report(logvisor::Info, _S("initialized project at '%s/.hecl'"), m_dir->c_str());
return 0;
}

View File

@ -137,10 +137,6 @@ public:
FindSelectedItems({*m_useProj, _S("")}, true);
}
~ToolPackage()
{
}
static void Help(HelpOutput& help)
{
help.secHead(_S("NAME"));
@ -212,6 +208,11 @@ public:
return 0;
}
void cancel()
{
m_useProj->interruptCook();
}
};
#endif // CTOOL_PACKAGE

View File

@ -67,9 +67,13 @@ static void printHelp(const hecl::SystemChar* pname)
/* Regex patterns */
static const hecl::SystemRegex regOPEN(_S("-o([^\"]*|\\S*)"), std::regex::ECMAScript|std::regex::optimize);
static ToolBase* ToolPtr = nullptr;
/* SIGINT will gracefully close blender connections and delete blends in progress */
static void SIGINTHandler(int sig)
{
if (ToolPtr)
ToolPtr->cancel();
hecl::blender::Connection::Shutdown();
logvisor::KillProcessTree();
exit(1);
@ -249,7 +253,7 @@ int main(int argc, const char** argv)
system("PAUSE");
#endif
delete newProj;
return -1;
return 1;
}
project.reset(newProj);
info.project = newProj;
@ -296,7 +300,7 @@ int main(int argc, const char** argv)
#if WIN_PAUSE
system("PAUSE");
#endif
return -1;
return 1;
}
if (info.verbosityLevel)
@ -305,14 +309,16 @@ int main(int argc, const char** argv)
/* Run tool */
ErrorRef = logvisor::ErrorCount;
ToolPtr = tool.get();
int retval = tool->run();
ToolPtr = nullptr;
if (logvisor::ErrorCount > ErrorRef)
{
hecl::blender::Connection::Shutdown();
#if WIN_PAUSE
system("PAUSE");
#endif
return -1;
return 1;
}
hecl::blender::Connection::Shutdown();

View File

@ -122,6 +122,8 @@ public:
ClientProcess* cp=nullptr)
{(void)path;}
virtual void interruptCook() {}
const DataSpecEntry* getDataSpecEntry() const {return m_specEntry;}
};

View File

@ -562,6 +562,8 @@ bool Project::packagePath(const ProjectPath& path, const hecl::MultiProgressPrin
void Project::interruptCook()
{
if (m_lastPackageSpec)
m_lastPackageSpec->interruptCook();
}
bool Project::cleanPath(const ProjectPath& path, bool recursive)