예제 #1
0
//////////////////////////////////////////////////////////////////////////////////
// 添加pInBuf(当它是文件)/pInBuf下的所有子文件(当它是目录)到队列
// pInBuf		 - 待添加文件(展开目录)
// callback		 - 回调函数
// pcb			 - 回调函数参数
//////////////////////////////////////////////////////////////////////////////////
DWORD AppendFileToQueue(PTSTR pInBuf, CallBack callback, struct CB *pcb)
{	
	if (FILE_ATTRIBUTE_DIRECTORY == GetFileAttributes(pInBuf))
	{
		ExpandDirectory(pInBuf, callback, pcb);
	}
	else
	{
		callback(pcb, pInBuf);
	}
	return 0;
}
예제 #2
0
int ExpandDirectory(PTSTR lpszPath, CallBack callback, struct CB* pcb)
{
	static const DWORD MemAllocStep = 1024*MAX_PATH;
	wchar_t			lpFind[MAXPATH], lpSearch[MAXPATH], lpPath[MAXPATH];
	HANDLE			hFindFile;
	WIN32_FIND_DATA FindData;
	int				cnt = 0;

	// Path\*.*
	StringCchCopy(lpPath, MAXPATH, lpszPath);
	StringCchCat(lpPath, MAXPATH, L"\\");
	StringCchCopy(lpSearch, MAXPATH, lpPath);
	StringCchCat(lpSearch, MAXPATH, L"*.*");

	if (INVALID_HANDLE_VALUE != (hFindFile = FindFirstFile(lpSearch, &FindData)))
	{
		do
		{
			// 完整文件名
			StringCchCopy(lpFind, MAXPATH, lpPath);
			StringCchCat(lpFind, MAXPATH, FindData.cFileName);

			if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				if (FindData.cFileName[0] != '.')
					ExpandDirectory(lpFind, callback, pcb);
			}
			else
			{
				callback(pcb, lpFind);
			}
		}while(FindNextFile(hFindFile, &FindData));
		FindClose(hFindFile);
		return 0;
	}
	return -2;
}
예제 #3
0
//------------------------------------------------------------------------------
// Purpose    : Parse the command line and config file
// Parameters : argc, argv
// Returns    : Filled-in Options structure
//------------------------------------------------------------------------------
Options GetOptions(int argc, char * const argv[])
{

  // Read command line options
  Options opt;
  po::options_description desc("Allowed options");
  desc.add_options()
  ("help,h", "Show this message")
  ("callsign", po::value<string>(&opt.callsign), "Sender's Callsign")
  ("sequence", po::value<int>(&opt.sequence)->default_value(1),
   "Message Sequence Number")
  ("user", po::value<string>(&opt.user), "Google User Name")
  ("password", po::value<string>(&opt.password), "Google Password")
  ("from", po::value<string>(&opt.from), "FM Addee")
  ("to", po::value<string>(&opt.to), "TO Addee")
  ("info", po::value<string>(&opt.info), "INFO Addee")
  ("subject", po::value<string>(&opt.subject), "Message Subject")
  ("spreadsheet-name", po::value<string>(&opt.spreadsheet_name),
   "Spreadsheet Name")
  ("spreadsheet-id", po::value<string>(&opt.spreadsheet_id), "Spreadsheet ID")
  ("worksheet-name", po::value<string>(&opt.worksheet_name), "Worksheet Name")
  ("worksheet-id", po::value<string>(&opt.worksheet_id), "Worksheet ID")
  ;

  // Config file
  string config_file = ExpandDirectory("~/.thirteenrc");
  fs::path config_path(config_file);

  // Load configuration
  po::variables_map vm;
  try {
    po::store(po::parse_command_line(argc, argv, desc), vm);
    if(fs::exists(config_path)) {
      ifstream config_stream(config_file.c_str());
      po::store(po::parse_config_file(config_stream, desc), vm);
    }
  } catch(exception& e) {
    cerr << "Unable to parse command line: " << e.what() << endl;
    exit(1);
  }
  po::notify(vm);
  if (vm.count("help")) {
    cout << desc << "\n";
    exit(1);
  }

  // Test for errors
  vector<string> errors;
  if(!(opt.spreadsheet_name.size() || opt.spreadsheet_id.size())) {
    errors.push_back("Either a spreadsheet name or a spreadsheet"
                     " id must be specified");
  }
  if(!opt.user.size()) {
    errors.push_back("No Google Docs user specified");
  }
  if(!opt.password.size()) {
    errors.push_back("No Google Docs password specified");
  }
  if(!opt.from.size()) {
    errors.push_back("No FM addee specified");
  }
  if(!opt.to.size()) {
    errors.push_back("No TO addee specified");
  }
  if(!opt.info.size()) {
    errors.push_back("No INFO addee specified");
  }
  if(!opt.subject.size()) {
    errors.push_back("No subject specified");
  }
  if(errors.size()) {
    cout << "Error:" << endl;
    BOOST_FOREACH(string error, errors) {
      cout << "  " << error << endl;
    }
    exit(1);
  }