bool WeatherFile_Impl::makeUrlAbsolute(const openstudio::path& searchDirectory) { boost::optional<openstudio::path> currentPath = this->path(); if (currentPath){ if (currentPath->is_complete() && boost::filesystem::exists(*currentPath)) { return true; } openstudio::path newPath, workingPath(*currentPath); if (!currentPath->is_complete()) { newPath = boost::filesystem::system_complete(workingPath); LOG(Debug,"Current path '" << toString(*currentPath) << "' not complete. " << "After calling system_complete have '" << toString(newPath) << "'."); } if (newPath.empty() || !boost::filesystem::exists(newPath)) { newPath = searchDirectory / *currentPath; LOG(Debug,"Going to look for '" << toString(newPath) << "'."); } if (newPath.empty() || !boost::filesystem::exists(newPath)) { workingPath = toPath(currentPath->filename()); newPath = searchDirectory / workingPath; LOG(Debug,"Going to look for '" << toString(newPath) << "'."); } if (newPath.empty() || !boost::filesystem::exists(newPath)) { return false; } std::string weatherFileUrl = toString(toURL(newPath)); LOG(Debug,"Setting weather file url to " << weatherFileUrl); return setString(OS_WeatherFileFields::Url,weatherFileUrl); } return false; }
/** * 根据url数组下载文件 * @params urls 字符串数组,表示要下载的文件*/ void downloadFileFormArray(){ //循环遍历 urls , 获取元素url //解析出文件名,判断是否存在,存在则给用户选择 是否覆盖 isOverride? //除非输入 N 其它任何选项都是覆盖 //然后调用downlaodFileFromUrl(url, isOverride); int i = 0; FILE *file; while(strlen(urls[i]) != 0){ if(file = fopen(split(toURL(urls[i])),"r")){ printf("file %s is exist,put 1 to cover or put 0 to leave \n",split(toURL(urls[i]))); char c = fgetc(stdin); fclose(file); if (c != '1'){ while(getchar() != '\n'); i++; continue; } } downlaodFileFromUrl(toURL(urls[i++])); } return; }
boost::optional<WeatherFile> WeatherFile::setWeatherFile(Model& model, const openstudio::EpwFile& epwFile) { WeatherFile weatherFile = model.getUniqueModelObject<WeatherFile>(); weatherFile.setString(OS_WeatherFileFields::City, epwFile.city()); weatherFile.setString(OS_WeatherFileFields::StateProvinceRegion, epwFile.stateProvinceRegion()); weatherFile.setString(OS_WeatherFileFields::Country, epwFile.country()); weatherFile.setString(OS_WeatherFileFields::DataSource, epwFile.dataSource()); weatherFile.setString(OS_WeatherFileFields::WMONumber, epwFile.wmoNumber()); weatherFile.setDouble(OS_WeatherFileFields::Latitude, epwFile.latitude()); weatherFile.setDouble(OS_WeatherFileFields::Longitude, epwFile.longitude()); weatherFile.setDouble(OS_WeatherFileFields::TimeZone, epwFile.timeZone()); weatherFile.setDouble(OS_WeatherFileFields::Elevation, epwFile.elevation()); weatherFile.setString(OS_WeatherFileFields::Url, toString(toURL(epwFile.path()))); weatherFile.setString(OS_WeatherFileFields::Checksum, epwFile.checksum()); return weatherFile; }
bool WeatherFile_Impl::makeUrlRelative(const openstudio::path& basePath) { boost::optional<openstudio::path> currentPath = this->path(); if (currentPath){ openstudio::path newPath; if (basePath.empty()) { newPath = toPath(currentPath->filename()); } else { newPath = relativePath(*currentPath,basePath); } if (!newPath.empty()) { std::string weatherFileUrl = toString(toURL(newPath)); LOG(Debug,"Setting weather file url to " << weatherFileUrl); return setString(OS_WeatherFileFields::Url,weatherFileUrl); } } return false; }