| @@ -171,7 +171,7 @@ protected: | |||
| //============================================================================== | |||
| String getIntermediatesPath (const BuildConfiguration& config) const | |||
| { | |||
| return ".\\" + File::createLegalFileName (config.getName().trim()); | |||
| return prependDot (File::createLegalFileName (config.getName().trim())); | |||
| } | |||
| String getConfigTargetPath (const BuildConfiguration& config) const | |||
| @@ -185,8 +185,8 @@ protected: | |||
| if (binaryRelPath.isAbsolute()) | |||
| return binaryRelPath.toWindowsStyle(); | |||
| return ".\\" + binaryRelPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder) | |||
| .toWindowsStyle(); | |||
| return prependDot (binaryRelPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder) | |||
| .toWindowsStyle()); | |||
| } | |||
| String getPreprocessorDefs (const BuildConfiguration& config, const String& joinString) const | |||
| @@ -477,6 +477,12 @@ protected: | |||
| return versionParts.joinIntoString (","); | |||
| } | |||
| static String prependDot (const String& filename) | |||
| { | |||
| return FileHelpers::isAbsolutePath (filename) ? filename | |||
| : (".\\" + filename); | |||
| } | |||
| JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase); | |||
| }; | |||
| @@ -1221,14 +1227,14 @@ protected: | |||
| { | |||
| XmlElement* iconGroup = projectXml.createNewChildElement ("ItemGroup"); | |||
| XmlElement* e = iconGroup->createNewChildElement ("None"); | |||
| e->setAttribute ("Include", ".\\" + iconFile.getFileName()); | |||
| e->setAttribute ("Include", prependDot (iconFile.getFileName())); | |||
| } | |||
| if (hasResourceFile()) | |||
| { | |||
| XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup"); | |||
| XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile"); | |||
| e->setAttribute ("Include", ".\\" + rcFile.getFileName()); | |||
| e->setAttribute ("Include", prependDot (rcFile.getFileName())); | |||
| } | |||
| { | |||
| @@ -1364,7 +1370,7 @@ protected: | |||
| { | |||
| XmlElement* iconGroup = filterXml.createNewChildElement ("ItemGroup"); | |||
| XmlElement* e = iconGroup->createNewChildElement ("None"); | |||
| e->setAttribute ("Include", ".\\" + iconFile.getFileName()); | |||
| e->setAttribute ("Include", prependDot (iconFile.getFileName())); | |||
| e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName()); | |||
| } | |||
| @@ -1372,7 +1378,7 @@ protected: | |||
| { | |||
| XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup"); | |||
| XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile"); | |||
| e->setAttribute ("Include", ".\\" + rcFile.getFileName()); | |||
| e->setAttribute ("Include", prependDot (rcFile.getFileName())); | |||
| e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName()); | |||
| } | |||
| } | |||
| @@ -79,7 +79,7 @@ ProjectExporter* ProjectExporter::createNewExporter (Project& project, const int | |||
| File target (exp->getTargetFolder()); | |||
| if (FileHelpers::shouldPathsBeRelative (juceFolder.getFullPathName(), project.getFile().getFullPathName())) | |||
| exp->getJuceFolderValue() = juceFolder.getRelativePathFrom (project.getFile().getParentDirectory()); | |||
| exp->getJuceFolderValue() = FileHelpers::getRelativePathFrom (juceFolder, project.getFile().getParentDirectory()); | |||
| else | |||
| exp->getJuceFolderValue() = juceFolder.getFullPathName(); | |||
| @@ -679,7 +679,7 @@ void LibraryModule::addBrowsableCode (ProjectExporter& exporter, const Array<Fil | |||
| for (int i = 0; i < sourceFiles.size(); ++i) | |||
| { | |||
| const String pathWithinModule (sourceFiles.getReference(i).getRelativePathFrom (localModuleFolder)); | |||
| const String pathWithinModule (FileHelpers::getRelativePathFrom (sourceFiles.getReference(i), localModuleFolder)); | |||
| // (Note: in exporters like MSVC we have to avoid adding the same file twice, even if one of those instances | |||
| // is flagged as being excluded from the build, because this overrides the other and it fails to compile) | |||
| @@ -689,7 +689,7 @@ void LibraryModule::addBrowsableCode (ProjectExporter& exporter, const Array<Fil | |||
| pathWithinModule); | |||
| } | |||
| sourceGroup.addFile (localModuleFolder.getChildFile (moduleFile.getRelativePathFrom (moduleFolder)), -1, false); | |||
| sourceGroup.addFile (localModuleFolder.getChildFile (FileHelpers::getRelativePathFrom (moduleFile, moduleFolder)), -1, false); | |||
| sourceGroup.addFile (getInclude (localModuleFolder), -1, false); | |||
| exporter.getModulesGroup().state.addChild (sourceGroup.state.createCopy(), -1, nullptr); | |||
| @@ -306,8 +306,8 @@ File Project::resolveFilename (String filename) const | |||
| filename = replacePreprocessorDefs (getPreprocessorDefs(), filename) | |||
| .replaceCharacter ('\\', '/'); | |||
| if (File::isAbsolutePath (filename)) | |||
| return File (filename); | |||
| if (FileHelpers::isAbsolutePath (filename)) | |||
| return File::createFileWithoutCheckingPath (filename); // (avoid assertions for windows-style paths) | |||
| return getFile().getSiblingFile (filename); | |||
| } | |||
| @@ -330,7 +330,7 @@ String Project::getRelativePathForFile (const File& file) const | |||
| if (p1.upToFirstOccurrenceOf (File::separatorString, true, false) | |||
| .equalsIgnoreCase (p2.upToFirstOccurrenceOf (File::separatorString, true, false))) | |||
| { | |||
| filename = file.getRelativePathFrom (relativePathBase); | |||
| filename = FileHelpers::getRelativePathFrom (file, relativePathBase); | |||
| } | |||
| return filename; | |||
| @@ -187,7 +187,7 @@ namespace CodeHelpers | |||
| String createIncludeStatement (const File& includeFile, const File& targetFile) | |||
| { | |||
| return createIncludeStatement (FileHelpers::unixStylePath (includeFile.getRelativePathFrom (targetFile.getParentDirectory()))); | |||
| return createIncludeStatement (FileHelpers::unixStylePath (FileHelpers::getRelativePathFrom (includeFile, targetFile.getParentDirectory()))); | |||
| } | |||
| String createIncludeStatement (const String& includePath) | |||
| @@ -112,12 +112,19 @@ namespace FileHelpers | |||
| return path.replaceCharacter ('/', '\\'); | |||
| } | |||
| bool isAbsolutePath (const String& path) | |||
| { | |||
| return File::isAbsolutePath (path) | |||
| || path.startsWithChar ('/') // (needed because File::isAbsolutePath will ignore forward-slashes on Windows) | |||
| || path.startsWithChar ('$') | |||
| || path.startsWithChar ('~') | |||
| || (CharacterFunctions::isLetter (path[0]) && path[1] == ':') | |||
| || path.startsWithIgnoreCase ("smb:"); | |||
| } | |||
| static String appendPath (const String& path, const String& subpath) | |||
| { | |||
| if (File::isAbsolutePath (subpath) | |||
| || subpath.startsWithChar ('$') | |||
| || subpath.startsWithChar ('~') | |||
| || (CharacterFunctions::isLetter (subpath[0]) && subpath[1] == ':')) | |||
| if (isAbsolutePath (subpath)) | |||
| return subpath.replaceCharacter ('\\', '/'); | |||
| String path1 (path.replaceCharacter ('\\', '/')); | |||
| @@ -145,4 +152,15 @@ namespace FileHelpers | |||
| return path1.substring (0, commonBitLength).removeCharacters ("/:").isNotEmpty(); | |||
| } | |||
| String getRelativePathFrom (const File& file, const File& sourceFolder) | |||
| { | |||
| #if ! JUCE_WINDOWS | |||
| // On a non-windows machine, we can't know if a drive-letter path may be relative or not. | |||
| if (CharacterFunctions::isLetter (file.getFullPathName()[0]) && file.getFullPathName()[1] == ':') | |||
| return file.getFullPathName(); | |||
| #endif | |||
| return file.getRelativePathFrom (sourceFolder); | |||
| } | |||
| } | |||
| @@ -43,6 +43,10 @@ namespace FileHelpers | |||
| String windowsStylePath (const String& path); | |||
| bool shouldPathsBeRelative (String path1, String path2); | |||
| bool isAbsolutePath (const String& path); | |||
| // A windows-aware version of File::getRelativePath() | |||
| String getRelativePathFrom (const File& file, const File& sourceFolder); | |||
| } | |||
| //============================================================================== | |||
| @@ -53,7 +53,7 @@ public: | |||
| } | |||
| RelativePath (const File& file, const File& rootFolder, const RootFolder root_) | |||
| : path (file.getRelativePathFrom (rootFolder).replaceCharacter ('\\', '/')), root (root_) | |||
| : path (FileHelpers::getRelativePathFrom (file, rootFolder).replaceCharacter ('\\', '/')), root (root_) | |||
| { | |||
| } | |||
| @@ -67,7 +67,7 @@ public: | |||
| String getFileExtension() const { return getFakeFile().getFileExtension(); } | |||
| bool hasFileExtension (const String& extension) const { return getFakeFile().hasFileExtension (extension); } | |||
| bool isAbsolute() const { return isAbsolute (path); } | |||
| bool isAbsolute() const { return FileHelpers::isAbsolutePath (path); } | |||
| RelativePath withFileExtension (const String& extension) const | |||
| { | |||
| @@ -85,7 +85,7 @@ public: | |||
| RelativePath getChildFile (const String& subpath) const | |||
| { | |||
| if (isAbsolute (subpath)) | |||
| if (FileHelpers::isAbsolutePath (subpath)) | |||
| return RelativePath (subpath, root); | |||
| String p (toUnixStyle()); | |||
| @@ -100,7 +100,7 @@ public: | |||
| if (isAbsolute()) | |||
| return RelativePath (path, newRootType); | |||
| return RelativePath (originalRoot.getChildFile (toUnixStyle()).getRelativePathFrom (newRoot), newRootType); | |||
| return RelativePath (FileHelpers::getRelativePathFrom (originalRoot.getChildFile (toUnixStyle()), newRoot), newRootType); | |||
| } | |||
| private: | |||
| @@ -114,16 +114,6 @@ private: | |||
| static const File currentWorkingDirectory (File::getCurrentWorkingDirectory()); | |||
| return currentWorkingDirectory.getChildFile (path); | |||
| } | |||
| static bool isAbsolute (const String& path) | |||
| { | |||
| return File::isAbsolutePath (path) | |||
| || path.startsWithChar ('/') // (needed because File::isAbsolutePath will ignore forward-slashes on Windows) | |||
| || path.startsWithChar ('$') | |||
| || path.startsWithChar ('~') | |||
| || (CharacterFunctions::isLetter (path[0]) && path[1] == ':') | |||
| || path.startsWithIgnoreCase ("smb:"); | |||
| } | |||
| }; | |||