#include <windows.h>
#include <shellapi.h>
#include <stdio.h>
#include "st.h"

#ifdef NO_MAIN
extern "C" {
extern int trash_main(int argc, char* argv[]);
}
int trash_main(int argc, char* argv[])
#else 
int main(int argc, char* argv[]) 
#endif
{
   SHFILEOPSTRUCT shFileOpStruct;
   char szPath[MAX_PATH+10];

   if(argc < 2) {
      cout << "usage: trash <file>" << endl;
   }
   else {
      int result = 0;
      for(size_t i = 1; i < argc; i++) {
         memset(szPath, 0, MAX_PATH+10);
         strcpy(szPath, argv[i]);

         ZeroMemory(&shFileOpStruct, sizeof(SHFILEOPSTRUCT));
         shFileOpStruct.hwnd = NULL; 
         shFileOpStruct.wFunc = FO_DELETE;
         shFileOpStruct.pFrom = szPath;
         shFileOpStruct.fFlags = FOF_ALLOWUNDO |FOF_NOCONFIRMATION /*| FOF_NOERRORUI*/; 

         result = SHFileOperation(&shFileOpStruct);

         if(result != 0) 
            break;
      }

      if(result == 0) {
         cout << "File(s) successfully moved to Recycle Bin." << endl;
      } 
      else {
         cout << "Failed to move file(s) to Recycle Bin. Error code: " << result << endl;
      }
   }
   return 0;
}
