Esempio n. 1
0
std::string Maker::GetFileTime(const std::string &goal, const std::string &preferredPath, Time &timeval)
{
    std::string rv;
    if (goal.find_first_of(CmdFiles::DIR_SEP) != std::string::npos)
    {
        std::fstream fil(goal.c_str(), std::ios::in);
        if (fil != NULL)
        {
            fil.close();
            timeval = OS::GetFileTime(goal);
        }
    }
    else
    {
        std::string vpath = preferredPath + std::string(" .\\ ") + Eval::GetVPATH(goal);
        std::string sep = std::string(" ") + CmdFiles::PATH_SEP;
        while (vpath.size())
        {
            std::string cur = Eval::ExtractFirst(vpath, sep);
            if (cur[cur.size() -1] != CmdFiles::DIR_SEP[0])
                cur += CmdFiles::DIR_SEP;
            std::string name ;
            if (goal[0] != CmdFiles::DIR_SEP[0] && goal[1] != ':')
                name = cur + goal;
            else
                name = goal;
            if (cur != ".\\")
                filePaths[goal] = cur; // tentatively enter this as the goal path
                                    // this will collide if there are multiple paths and no file exists
                                    // and choose the last one
            std::fstream fil(name.c_str(), std::ios::in);
            if (fil != NULL)
            {
                fil.close();
                rv = cur; // return value is the path, with a slash on the end
                timeval = OS::GetFileTime(name);
                filePaths[goal] = cur;
                break;
            }
        }
    }
    if (ScanList(newFiles, goal) || ScanList(newFiles, rv + goal))
    {
        timeval = OS::GetCurrentTime();
    }
    else if (ScanList(oldFiles, goal) || ScanList(oldFiles, rv + goal))
    {
        timeval.Clear();
    }
    return rv;
}