void File::revealToUser() const { if (isDirectory()) startAsProcess(); else if (getParentDirectory().exists()) getParentDirectory().startAsProcess(); }
Result ZipFile::uncompressEntry (int index, const File& targetDirectory, bool shouldOverwriteFiles) { auto* zei = entries.getUnchecked (index); #if JUCE_WINDOWS auto entryPath = zei->entry.filename; #else auto entryPath = zei->entry.filename.replaceCharacter ('\\', '/'); #endif if (entryPath.isEmpty()) return Result::ok(); auto targetFile = targetDirectory.getChildFile (entryPath); if (entryPath.endsWithChar ('/') || entryPath.endsWithChar ('\\')) return targetFile.createDirectory(); // (entry is a directory, not a file) ScopedPointer<InputStream> in (createStreamForEntry (index)); if (in == nullptr) return Result::fail ("Failed to open the zip file for reading"); if (targetFile.exists()) { if (! shouldOverwriteFiles) return Result::ok(); if (! targetFile.deleteFile()) return Result::fail ("Failed to write to target file: " + targetFile.getFullPathName()); } if (! targetFile.getParentDirectory().createDirectory()) return Result::fail ("Failed to create target folder: " + targetFile.getParentDirectory().getFullPathName()); { FileOutputStream out (targetFile); if (out.failedToOpen()) return Result::fail ("Failed to write to target file: " + targetFile.getFullPathName()); out << *in; } targetFile.setCreationTime (zei->entry.fileTime); targetFile.setLastModificationTime (zei->entry.fileTime); targetFile.setLastAccessTime (zei->entry.fileTime); return Result::ok(); }
int main( int argc, char **argv) { char *exePath = argv[0]; char *exeDir = getParentDirectory(exePath); int exitStatus = 0; char *libDir = 0; /* check if single data file exists next to executable */ exitStatus += validateTestFile1(exeDir); /* check if directory (and all files/subdirs within) exists next to executable */ exitStatus += validateTestDir1(exeDir); libDir = joinPaths(exeDir, "lib"); /* check directory again, but in a different location, and a different name */ exitStatus += validateTestDir1_renamed(libDir, "testdir1_renamed"); free(libDir); free(exeDir); if (0 == exitStatus) { fprintf(stdout, "\nNo errors found. All files are present in the expected locations.\n"); } else { fprintf(stderr, "\nSome files were not found in the expected locations. See log above.\n"); } return exitStatus; }
File findDefaultModulesFolder (bool mustContainJuceCoreModule) { auto& windows = ProjucerApplication::getApp().mainWindowList; for (int i = windows.windows.size(); --i >= 0;) { if (auto* p = windows.windows.getUnchecked (i)->getProject()) { const File f (EnabledModuleList::findDefaultModulesFolder (*p)); if (isJuceModulesFolder (f) || (f.isDirectory() && ! mustContainJuceCoreModule)) return f; } } if (mustContainJuceCoreModule) return findDefaultModulesFolder (false); auto f = File::getSpecialLocation (File::currentApplicationFile); for (;;) { auto parent = f.getParentDirectory(); if (parent == f || ! parent.isDirectory()) break; if (isJuceFolder (parent)) return parent.getChildFile ("modules"); f = parent; } return {}; }
//returns : ERROR_OK, ERROR_INTEGRITY, ERROR_FREE_SPACE void extractFileToDir(LauncherProperties * props, WCHAR ** resultFile) { WCHAR * fileName = NULL; int64t * fileLength = NULL; DWORD crc = 0; writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "Extracting file ...", 1); readStringWithDebugW( props, & fileName, "file name"); fileLength = newint64_t(0, 0); readBigNumberWithDebug( props, fileLength, "file length "); readNumberWithDebug( props, &crc, "CRC32"); if(!isOK(props)) return; if(fileName!=NULL) { DWORD i=0; WCHAR * dir; resolveString(props, &fileName); for(i=0;i<getLengthW(fileName);i++) { if(fileName[i]==L'/') { fileName[i]=L'\\'; } } dir = getParentDirectory(fileName); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... extract to directory = ", 0); writeMessageW(props, OUTPUT_LEVEL_DEBUG, 0, dir, 1); checkFreeSpace(props, dir, fileLength); FREE(dir); if(isOK(props)) { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... starting data extraction", 1); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... output file is ", 0); writeMessageW(props, OUTPUT_LEVEL_DEBUG, 0, fileName, 1); extractDataToFile(props, fileName, fileLength, crc); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... extraction finished", 1); *resultFile = fileName; } else { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... data extraction canceled", 1); } } else { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "Error! File name can`t be null. Seems to be integrity error!", 1); *resultFile = NULL; props -> status = ERROR_INTEGRITY; } FREE(fileLength); return; }
bool File::isAChildOf (const File& potentialParent) const { if (potentialParent.fullPath.isEmpty()) return false; const String ourPath (getPathUpToLastSlash()); if (compareFilenames (potentialParent.fullPath, ourPath) == 0) return true; if (potentialParent.fullPath.length() >= ourPath.length()) return false; return getParentDirectory().isAChildOf (potentialParent); }
void installJVM(LauncherProperties * props, LauncherResource *jvm) { WCHAR * command = NULL; WCHAR * jvmDir = getParentDirectory(jvm->resolved); jvmDir = appendStringW(jvmDir, L"\\_jvm"); createDirectory(props, jvmDir); if(!isOK(props)) { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1, "... cannot create dir for JVM extraction :", 0); writeMessageW(props, OUTPUT_LEVEL_DEBUG, 1, jvmDir, 1); FREE(jvmDir); return; } appendCommandLineArgument(&command, jvm->resolved); appendCommandLineArgument(&command, L"-d"); appendCommandLineArgument(&command, jvmDir); executeCommand(props, command, jvmDir, JVM_EXTRACTION_TIMEOUT, props->stdoutHandle, props->stderrHandle, NORMAL_PRIORITY_CLASS); FREE(command); if(!isOK(props)) { if(props->status==ERROR_PROCESS_TIMEOUT) { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1, "... could not extract JVM : timeout", 1); } else { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1, "... an error occured during running JVM extraction file", 1); } props->exitCode = props->status; } else { WCHAR * unpack200exe = appendStringW(appendStringW(NULL, jvmDir), UNPACK200_EXE_SUFFIX); if(fileExists(unpack200exe)) { unpackJars(props, jvmDir, jvmDir, unpack200exe); } else { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1, "... no unpack200 command", 1); props->status = ERROR_BUNDLED_JVM_EXTRACTION; } if(!isOK(props)) { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1, "Could not unpack200 the JVM jars", 1); } FREE(unpack200exe); } FREE(jvm->resolved); jvm->resolved = jvmDir; }
bool File::isAChildOf (const File& potentialParent) const { if (potentialParent == File::nonexistent) return false; const String ourPath (getPathUpToLastSlash()); #if NAMES_ARE_CASE_SENSITIVE if (potentialParent.fullPath == ourPath) #else if (potentialParent.fullPath.equalsIgnoreCase (ourPath)) #endif { return true; } else if (potentialParent.fullPath.length() >= ourPath.length()) { return false; } else { return getParentDirectory().isAChildOf (potentialParent); } }
bool File::isRoot() const { return fullPath.isNotEmpty() && *this == getParentDirectory(); }
void LibraryModule::addSettingsForModuleToExporter (ProjectExporter& exporter, ProjectSaver& projectSaver) const { auto& project = exporter.getProject(); const auto moduleRelativePath = exporter.getModuleFolderRelativeToProject (getID()); exporter.addToExtraSearchPaths (moduleRelativePath.getParentDirectory()); String libDirPlatform; if (exporter.isLinux()) libDirPlatform = "Linux"; else if (exporter.isCodeBlocks() && exporter.isWindows()) libDirPlatform = "MinGW"; else libDirPlatform = exporter.getTargetFolder().getFileName(); const auto libSubdirPath = String (moduleRelativePath.toUnixStyle() + "/libs/") + libDirPlatform; const auto moduleLibDir = File (project.getProjectFolder().getFullPathName() + "/" + libSubdirPath); if (moduleLibDir.exists()) exporter.addToModuleLibPaths (RelativePath (libSubdirPath, moduleRelativePath.getRoot())); const auto extraInternalSearchPaths = moduleInfo.getExtraSearchPaths().trim(); if (extraInternalSearchPaths.isNotEmpty()) { StringArray paths; paths.addTokens (extraInternalSearchPaths, true); for (int i = 0; i < paths.size(); ++i) exporter.addToExtraSearchPaths (moduleRelativePath.getChildFile (paths.getReference(i))); } { const String extraDefs (moduleInfo.getPreprocessorDefs().trim()); if (extraDefs.isNotEmpty()) exporter.getExporterPreprocessorDefs() = exporter.getExporterPreprocessorDefsString() + "\n" + extraDefs; } { Array<File> compiled; auto& modules = project.getModules(); auto id = getID(); const File localModuleFolder = modules.shouldCopyModuleFilesLocally (id).getValue() ? project.getLocalModuleFolder (id) : moduleInfo.getFolder(); findAndAddCompiledUnits (exporter, &projectSaver, compiled); if (modules.shouldShowAllModuleFilesInProject (id).getValue()) addBrowseableCode (exporter, compiled, localModuleFolder); } if (exporter.isXcode()) { auto& xcodeExporter = dynamic_cast<XcodeProjectExporter&> (exporter); if (project.isAUPluginHost()) xcodeExporter.xcodeFrameworks.addTokens (xcodeExporter.isOSX() ? "AudioUnit CoreAudioKit" : "CoreAudioKit", false); const String frameworks (moduleInfo.moduleInfo [xcodeExporter.isOSX() ? "OSXFrameworks" : "iOSFrameworks"].toString()); xcodeExporter.xcodeFrameworks.addTokens (frameworks, ", ", {}); parseAndAddLibs (xcodeExporter.xcodeLibs, moduleInfo.moduleInfo [exporter.isOSX() ? "OSXLibs" : "iOSLibs"].toString()); } else if (exporter.isLinux()) { parseAndAddLibs (exporter.linuxLibs, moduleInfo.moduleInfo ["linuxLibs"].toString()); parseAndAddLibs (exporter.linuxPackages, moduleInfo.moduleInfo ["linuxPackages"].toString()); } else if (exporter.isWindows()) { if (exporter.isCodeBlocks()) parseAndAddLibs (exporter.mingwLibs, moduleInfo.moduleInfo ["mingwLibs"].toString()); else parseAndAddLibs (exporter.windowsLibs, moduleInfo.moduleInfo ["windowsLibs"].toString()); } else if (exporter.isAndroid()) { parseAndAddLibs (exporter.androidLibs, moduleInfo.moduleInfo ["androidLibs"].toString()); } }
Path Path::getSiblingFile (const std::string& fileName) const { return getParentDirectory().getChildFile (fileName); }