#include <iostream>
#include <string>
#include <shlobj.h>
#include <windows.h>
#include "file.h"
#include "st.h"

using namespace std;
using namespace io_tools;

class ln {
public:
   int run(int argc, char ** argv) {
      int rc = 0;
      if(argc == 3) {
         string file1 = argv[1];
         string file2 = argv[2];
         if(file1.size() && file2.size()) {
            if(IsUserAnAdmin()) {
               if(File(file1).is_directory()) {
                  if(CreateSymbolicLink(file2.c_str(), file1.c_str(), SYMBOLIC_LINK_FLAG_DIRECTORY)) {

                  }
                  else {
                     cerr << "unable to create shortcut..." << endl;
                     rc = 1;
                  }
               }
               else {
                  if(CreateSymbolicLink(file2.c_str(), file1.c_str(), 0x0)) {

                  }
                  else {
                     cerr << "unable to create shortcut..." << endl;
                     rc = 1;
                  }
               }
            }
            else {
               cerr << "you must be an administer to create a shortcut..." << endl;
               rc = 1;
            }
         }
         else {
            cerr << "usage: shortcut <file1> <file2>" << endl;
            rc = 1;
         }
      }
      else {
         cerr << "usage: shortcut <file1> <file2>" << endl;
         rc = 1;
      }
      return rc;
   }
};


#ifdef NO_MAIN
extern "C" {
extern int ln_main(int argc, char ** argv);
}
int ln_main(int argc, char ** argv)
#else
int main(int argc, char ** argv)
#endif
{
   ln LN;
   LN.run(argc,argv);
   return 0;
}
