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::VerbosityLevel = info.verbosityLevel;
hecl::GuiMode = info.gui; hecl::GuiMode = info.gui;
} }
virtual ~ToolBase() {} virtual ~ToolBase() = default;
virtual hecl::SystemString toolName() const=0; virtual hecl::SystemString toolName() const=0;
virtual int run()=0; virtual int run()=0;
virtual void cancel() {}
inline operator bool() const {return m_good;} inline operator bool() const {return m_good;}
}; };

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -122,6 +122,8 @@ public:
ClientProcess* cp=nullptr) ClientProcess* cp=nullptr)
{(void)path;} {(void)path;}
virtual void interruptCook() {}
const DataSpecEntry* getDataSpecEntry() const {return m_specEntry;} 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() void Project::interruptCook()
{ {
if (m_lastPackageSpec)
m_lastPackageSpec->interruptCook();
} }
bool Project::cleanPath(const ProjectPath& path, bool recursive) bool Project::cleanPath(const ProjectPath& path, bool recursive)