コード例 #1
0
ファイル: dokanctl.c プロジェクト: cnhup/encfs4win-reloaded
int __cdecl
wmain(int argc, PWCHAR argv[])
{
	size_t	i;
    WCHAR	fileName[MAX_PATH];
    WCHAR	driverFullPath[MAX_PATH] = { 0 };
    WCHAR	mounterFullPath[MAX_PATH] = { 0 };
    WCHAR	type;

    //setlocale(LC_ALL, "");

    GetModuleFileName(NULL, fileName, MAX_PATH);
    
    // search the last "\"
    for(i = wcslen(fileName) - 1; i > 0 && fileName[i] != L'\\'; --i)
    {
        ;
    }
    fileName[i] = L'\0';

    wcscpy_s(mounterFullPath, MAX_PATH, fileName);
    wcscat_s(mounterFullPath, MAX_PATH, L"\\mounter.exe");
    fwprintf(stderr, L"mounter path %s\n", mounterFullPath);

    GetSystemDirectory(driverFullPath, MAX_PATH);
    wcscat_s(driverFullPath, MAX_PATH, L"\\drivers\\dokan.sys");

    fwprintf(stderr, L"driver path %s\n", driverFullPath);
    

    if (GetOption(argc, argv, 1) == L'v') {
        fprintf(stderr, "dokanctl : %s %s\n", __DATE__, __TIME__);
        fprintf(stderr, "Dokan version : %d\n", DokanVersion());
        fprintf(stderr, "Dokan driver version : 0x%X\n", DokanDriverVersion());
        return 0;
    
    } else if (GetOption(argc, argv, 1) == L'm') {
        return ShowMountList();

    } else if (GetOption(argc, argv, 1) == L'u' && argc == 3) {
        return Unmount(argv[2], FALSE);

    } else if (GetOption(argc, argv, 1) == L'u' &&
                GetOption(argc, argv, 3) == L'f' && argc == 4) {
        return Unmount(argv[2], TRUE);

    } else if (argc < 3 || wcslen(argv[1]) != 2 || argv[1][0] != L'/' ) {
        return ShowUsage();
    }

    type = towlower(argv[2][0]);

    switch(towlower(argv[1][1])) {
    case L'i':
        if (type ==  L'd') {
            if (DokanServiceInstall(DOKAN_DRIVER_SERVICE,
                                    SERVICE_FILE_SYSTEM_DRIVER,
                                    driverFullPath))
                fprintf(stderr, "driver install ok");
            else
                fprintf(stderr, "driver install failed");

        } else if (type == L's') {
            if (DokanServiceInstall(DOKAN_MOUNTER_SERVICE,
                                    SERVICE_WIN32_OWN_PROCESS,
                                    mounterFullPath))
                fprintf(stderr, "mounter install ok");
            else
                fprintf(stderr, "mounter install failed");
        
        } else if (type == L'a') {
            if (DokanServiceInstall(DOKAN_DRIVER_SERVICE,
                                    SERVICE_FILE_SYSTEM_DRIVER,
                                    driverFullPath))
                fprintf(stderr, "driver install ok");
            else
                fprintf(stderr, "driver install failed");

            if (DokanServiceInstall(DOKAN_MOUNTER_SERVICE,
                                    SERVICE_WIN32_OWN_PROCESS,
                                    mounterFullPath))
                fprintf(stderr, "mounter install ok");
            else
                fprintf(stderr, "mounter install failed");
        } else if (type == L'n') {
            if (DokanNetworkProviderInstall())
                fprintf(stderr, "network provider install ok");
            else
                fprintf(stderr, "network provider install failed");
        }
        break;

    case L'r':
        if (type == L'd') {
            if (DokanServiceDelete(DOKAN_DRIVER_SERVICE))
                fprintf(stderr, "driver remove ok");
            else
                fprintf(stderr, "driver remvoe failed");
        
        } else if (type == L's') {
            if (DokanServiceDelete(DOKAN_MOUNTER_SERVICE))
                fprintf(stderr, "mounter remove ok");
            else
                fprintf(stderr, "mounter remvoe failed");	
        
        } else if (type == L'a') {
            if (DokanServiceDelete(DOKAN_MOUNTER_SERVICE))
                fprintf(stderr, "mounter remove ok");
            else
                fprintf(stderr, "mounter remvoe failed");	

            if (DokanServiceDelete(DOKAN_DRIVER_SERVICE))
                fprintf(stderr, "driver remove ok");
            else
                fprintf(stderr, "driver remvoe failed");
        } else if (type == L'n') {
            if (DokanNetworkProviderUninstall())
                fprintf(stderr, "network provider remove ok");
            else
                fprintf(stderr, "network provider remove failed");
        }
        break;
    case L'd':
        if (L'0' <= type && type <= L'9') {
            ULONG mode = type - L'0';
            if (DokanSetDebugMode(mode)) {
                fprintf(stderr, "set debug mode ok");
            } else {
                fprintf(stderr, "set debug mode failed");
            }
        }
        break;
    default:
        fprintf(stderr, "unknown option");
    }
    

    return 0;
}
コード例 #2
0
ファイル: dokanctl.c プロジェクト: MaMic/dokany
int __cdecl wmain(int argc, PWCHAR argv[]) {
  size_t i;
  WCHAR fileName[MAX_PATH];
  WCHAR driverFullPath[MAX_PATH] = {0};
  WCHAR mounterFullPath[MAX_PATH] = {0};
  WCHAR type;
  PVOID wow64OldValue;

  DokanUseStdErr(TRUE); // Set dokan library debug output

  Wow64DisableWow64FsRedirection(&wow64OldValue); //Disable system32 direct
  // setlocale(LC_ALL, "");

  GetModuleFileName(NULL, fileName, MAX_PATH);

  // search the last "\"
  for (i = wcslen(fileName) - 1; i > 0 && fileName[i] != L'\\'; --i) {
    ;
  }
  fileName[i] = L'\0';

  wcscpy_s(mounterFullPath, MAX_PATH, fileName);
  wcscat_s(mounterFullPath, MAX_PATH, L"\\mounter.exe");
  fwprintf(stderr, L"Mounter path: '%s'\n", mounterFullPath);

  ExpandEnvironmentStringsW(DOKAN_DRIVER_FULL_PATH, driverFullPath, MAX_PATH);

  fwprintf(stderr, L"Driver path: '%s'\n", driverFullPath);

  if (GetOption(argc, argv, 1) == L'v') {
    fprintf(stderr, "dokanctl : %s %s\n", __DATE__, __TIME__);
    fprintf(stderr, "Dokan version : %d\n", DokanVersion());
    fprintf(stderr, "Dokan driver version : 0x%lx\n", DokanDriverVersion());
    return EXIT_SUCCESS;

  } else if (GetOption(argc, argv, 1) == L'm') {
    return ShowMountList();

  } else if (GetOption(argc, argv, 1) == L'u' && argc == 3) {
    return Unmount(argv[2], FALSE);

  } else if (GetOption(argc, argv, 1) == L'u' &&
             GetOption(argc, argv, 3) == L'f' && argc == 4) {
    return Unmount(argv[2], TRUE);

  } else if (argc < 3 || wcslen(argv[1]) != 2 || argv[1][0] != L'/') {
    return ShowUsage();
  }

  type = towlower(argv[2][0]);

  switch (towlower(argv[1][1])) {
  case L'i':
    if (type == L'd') {

      return InstallDriver(driverFullPath);

    } else if (type == L's') {

      return InstallMounter(mounterFullPath);

    } else if (type == L'a') {

      if (InstallDriver(driverFullPath) == EXIT_FAILURE)
        return EXIT_FAILURE;

      if (InstallMounter(mounterFullPath) == EXIT_FAILURE)
        return EXIT_FAILURE;

    } else if (type == L'n') {
      if (DokanNetworkProviderInstall())
        fprintf(stderr, "network provider install ok\n");
      else
        fprintf(stderr, "network provider install failed\n");
    }
    break;

  case L'r':
    if (type == L'd') {

      return DeleteDokanService(DOKAN_DRIVER_SERVICE);

    } else if (type == L's') {

      return DeleteDokanService(DOKAN_MOUNTER_SERVICE);

    } else if (type == L'a') {

      if (DeleteDokanService(DOKAN_MOUNTER_SERVICE) == EXIT_FAILURE)
        return EXIT_FAILURE;

      if (DeleteDokanService(DOKAN_DRIVER_SERVICE) == EXIT_FAILURE)
        return EXIT_FAILURE;

    } else if (type == L'n') {
      if (DokanNetworkProviderUninstall())
        fprintf(stderr, "network provider remove ok\n");
      else
        fprintf(stderr, "network provider remove failed\n");
    }
    break;
  case L'd':
    if (L'0' <= type && type <= L'9') {
      ULONG mode = type - L'0';
      if (DokanSetDebugMode(mode)) {
        fprintf(stderr, "set debug mode ok\n");
      } else {
        fprintf(stderr, "set debug mode failed\n");
      }
    }
    break;
  default:
    fprintf(stderr, "unknown option\n");
  }

  return EXIT_SUCCESS;
}