]> git.lizzy.rs Git - minetest.git/blobdiff - src/porting.cpp
New kind of tool speed and wear calculation thingy
[minetest.git] / src / porting.cpp
index f349c0ce5e8c877660b7beab497145b57eee76a5..0adc955a94f77b28861a5bd8b4c00e118feeab09 100644 (file)
@@ -56,9 +56,10 @@ void sigint_handler(int sig)
                dstream<<DTIME<<"INFO: sigint_handler(): "
                                <<"Ctrl-C pressed, shutting down."<<std::endl;
                
-               dstream<<DTIME<<"INFO: sigint_handler(): "
+               // Comment out for less clutter when testing scripts
+               /*dstream<<DTIME<<"INFO: sigint_handler(): "
                                <<"Printing debug stacks"<<std::endl;
-               debug_stacks_print();
+               debug_stacks_print();*/
 
                g_killed = true;
        }
@@ -75,10 +76,46 @@ void signal_handler_init(void)
 }
 
 #else // _WIN32
+       #include <signal.h>
+       #include <windows.h>
+       
+       BOOL WINAPI event_handler(DWORD sig)
+       {
+               switch(sig)
+               {
+               case CTRL_C_EVENT:
+               case CTRL_CLOSE_EVENT:
+               case CTRL_LOGOFF_EVENT:
+               case CTRL_SHUTDOWN_EVENT:
+
+                       if(g_killed == false)
+                       {
+                               dstream<<DTIME<<"INFO: event_handler(): "
+                                               <<"Ctrl+C, Close Event, Logoff Event or Shutdown Event, shutting down."<<std::endl;
+                               // Comment out for less clutter when testing scripts
+                               /*dstream<<DTIME<<"INFO: event_handler(): "
+                                               <<"Printing debug stacks"<<std::endl;
+                               debug_stacks_print();*/
+
+                               g_killed = true;
+                       }
+                       else
+                       {
+                               (void)signal(SIGINT, SIG_DFL);
+                       }
 
+                       break;
+               case CTRL_BREAK_EVENT:
+                       break;
+               }
+               
+               return TRUE;
+       }
+       
 void signal_handler_init(void)
 {
-       // No-op
+       dstream<<"signal_handler_init()"<<std::endl;
+       SetConsoleCtrlHandler( (PHANDLER_ROUTINE)event_handler,TRUE);
 }
 
 #endif
@@ -90,6 +127,11 @@ void signal_handler_init(void)
 std::string path_data = ".." DIR_DELIM "data";
 std::string path_userdata = "..";
 
+std::string getDataPath(const char *subpath)
+{
+       return path_data + DIR_DELIM + subpath;
+}
+
 void pathRemoveFile(char *path, char delim)
 {
        // Remove filename and path delimiter