//// Sets the input value to a time in the future
//int FindNextTimeInTheFuture(UINT64& nextTime, UINT64 interval)
//{
//    int skipped = 0;
//
//    UINT64 now = internalTime::Now() + oneSecond / 100;
//
//    if (nextTime <= now)
//    {
//        UINT64 diff = now - nextTime;
//        skipped = static_cast<int>((diff / interval) + 1);
//        nextTime += skipped * interval;
//    }
//
//    return skipped;
//}
//
// Interpret the configuration file
// all lines that start with ';' are comments
// valid lines have the format
// [url] [dest] [hh:mm:ss] [hh:mm:ss]
// where the first [hh:mm:ss] is the time of day to start downloading
// and the second is the amount of time between downloads
vector<queuedFile> ProcessConfig(vector<string> const& validLines)
{
    vector<queuedFile> retv;

    for(vector<string>::const_iterator cit = validLines.begin(); cit < validLines.end(); ++cit)
    {
        queuedFile qf;
        vector<string> fields = ConvertLineToFields(*cit);
    
        if (fields.size() < 4)
        {
            // Malformed line found
            UCSBUtility::LogError(__FUNCTION__, __FILE__, __LINE__, "skipping malformed line:\n%s\n", cit->c_str());
            continue;
        }

        // Check to see if the first field is FLIR
        if (fields[0] == "FLIR")
        {
            qf.isFLIR = true;

        }
        else
        {
            // Now just extract the data
            wstring source = StupidConvertToWString(fields[0]);
            URL_COMPONENTS urlParts = { sizeof(URL_COMPONENTS) };
            urlParts.dwHostNameLength = source.length();
            urlParts.dwUrlPathLength = source.length();
            InternetCrackUrl(source.c_str(), 0, 0, &urlParts);
            qf.sourceServer = wstring(urlParts.lpszHostName, urlParts.lpszHostName + urlParts.dwHostNameLength);
            qf.sourceResource = wstring (urlParts.lpszUrlPath, urlParts.lpszUrlPath + urlParts.dwUrlPathLength);

        }

        qf.destinationRootName = StupidConvertToWString(fields[1]);
        qf.startTime = ConvertStringToInt64Time(fields[2]);
        qf.downloadInterval = ConvertStringToInt64Time(fields[3]);
        
        UINT64 now = internalTime::Now();
        
        // If we have a don't care state, for start time use now
        if (qf.startTime == 0)
        {
            qf.startTime = now;
        }
        else
        {
            qf.startTime = ConvertStringToInt64TimeToday(fields[2]);
            FindNextTimeInTheFuture(qf.startTime, qf.downloadInterval);
        }

        if (qf.isFLIR)
        {
            if (fields.size() <= 4)
            {
                UCSBUtility::LogError(__FUNCTION__, __FILE__, __LINE__, "skipping malformed line:\n%s\n", cit->c_str());
                continue;
            }

            qf.flatFieldFrameInterval = atoi(fields[4].c_str());
        }
        else if (fields.size() > 4)
        {
            qf.username = StupidConvertToWString(fields[4]);
        }

        if (fields.size() > 5)
        {
            qf.password = StupidConvertToWString(fields[5]);
        }

        retv.push_back(qf);        
    }

    return retv;
}