Beispiel #1
0
static void inputCommand(void)
{
	char command[20];

	printf("Type 'help' to see help\n\n");

	while (true) {
		fgets(command, 20, stdin);

		if (command[strlen(command) - 1] == '\n') {
			command[strlen(command) - 1] = '\0';
		}

		if (_stricmp(command, "about") == 0) {
			printAbout();
		} else if (_stricmp(command, "help") == 0) {
			printHelp();
		} else if (_stricmp(command, "log on") == 0) {
			g_RPCServer.SetLogOn(true);
		} else if (_stricmp(command, "log off") == 0) {
			g_RPCServer.SetLogOn(false);
		} else if (_stricmp(command, "list") == 0) {
			printList();
		} else if (_stricmp(command, "quit") == 0) {
			if (g_MountProg.GetMountNumber() == 0) {
				break;
			} else {
				printConfirmQuit();
				fgets(command, 20, stdin);

				if (command[0] == 'y' || command[0] == 'Y') {
					break;
				}
			}
		} else if (_stricmp(command, "refresh") == 0) {
			g_MountProg.Refresh();
		} else if (_stricmp(command, "reset") == 0) {
			g_RPCServer.Set(PROG_NFS, NULL);
		} else if (strcmp(command, "") != 0) {
			printf("Unknown command: '%s'\n", command);
			printf("Type 'help' to see help\n");
		}
	}
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    std::vector<std::vector<std::string>> pPaths;
    char *pPath = NULL;
	bool pathFile = false;

    WSADATA wsaData;

    printAbout();

    if (argc < 2) {
        pPath = strrchr(argv[0], '\\');
        pPath = pPath == NULL ? argv[0] : pPath + 1;
        printUsage(pPath);
        return 1;
    }
  
    g_nUID = g_nGID = 0;
    g_bLogOn = true;
    g_sFileName = NULL;

    for (int i = 1; i < argc; i++) {//parse parameters
        if (_stricmp(argv[i], "-id") == 0) {
            g_nUID = atoi(argv[++i]);
            g_nGID = atoi(argv[++i]);
        } else if (_stricmp(argv[i], "-log") == 0) {
            g_bLogOn = _stricmp(argv[++i], "off") != 0;           
        } else if (_stricmp(argv[i], "-pathFile") == 0) {
            g_sFileName = argv[++i];

			if (g_MountProg.SetPathFile(g_sFileName) == false) {
                printf("Can't open file %s.\n", g_sFileName);
                return 1;
			} else {
				g_MountProg.Refresh();
				pathFile = true;
			}
        } else if (i == argc - 2) {
            pPath = argv[argc - 2];  //path is before the last parameter

            char *pCurPathAlias = argv[argc - 1]; //path alias is the last parameter

            if (pPath != NULL || pCurPathAlias != NULL) {
                std::vector<std::string> pCurPaths;
                pCurPaths.push_back(std::string(pPath));
                pCurPaths.push_back(std::string(pCurPathAlias));
                pPaths.push_back(pCurPaths);
            }

            break;
        } else if (i == argc - 1) {
            char *pPath = argv[argc - 1];  //path is the last parameter

            if (pPath != NULL) {
                char curPathAlias[MAXPATHLEN];
                strcpy_s(curPathAlias, pPath);
                char *pCurPathAlias = curPathAlias;

                std::vector<std::string> pCurPaths;
                pCurPaths.push_back(std::string(pPath));
                pCurPaths.push_back(std::string(pCurPathAlias));
                pPaths.push_back(pCurPaths);
            }

            break;
        }
    }

    HWND console = GetConsoleWindow();

    if (g_bLogOn == false && IsWindow(console)) {
        ShowWindow(console, SW_HIDE); // hides the window
    }

	if (pPaths.size() <= 0 && !pathFile) {
        printf("No paths to mount\n");
        return 1;
    }

    WSAStartup(0x0101, &wsaData);
    start(pPaths);
    WSACleanup();

    return 0;
}