From 51186c9f7ccac1d24bd0f8d1e5084cb37d508097 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 27 Apr 2024 10:58:00 +0200 Subject: [PATCH] Clean water File(const String&) usage Signed-off-by: falkTX --- source/backend/CarlaStandaloneNSM.cpp | 22 ++-------- source/backend/engine/CarlaEngine.cpp | 25 +++++------ source/backend/engine/CarlaEngineBridge.cpp | 26 +++--------- source/backend/plugin/CarlaPlugin.cpp | 24 ++--------- source/backend/plugin/CarlaPluginBridge.cpp | 16 +++---- source/backend/plugin/CarlaPluginJSFX.cpp | 8 ++-- source/backend/utils/CachedPlugins.cpp | 4 +- source/backend/utils/PluginDiscovery.cpp | 10 ++--- source/bridges-plugin/CarlaBridgePlugin.cpp | 20 ++------- source/includes/CarlaNativePrograms.hpp | 6 +-- .../modules/water/files/DirectoryIterator.cpp | 4 +- source/modules/water/files/File.cpp | 42 ++++++++----------- source/modules/water/files/File.h | 18 +++----- source/native-plugins/midi-file.cpp | 5 +-- source/utils/CarlaDssiUtils.cpp | 9 ++-- 15 files changed, 81 insertions(+), 158 deletions(-) diff --git a/source/backend/CarlaStandaloneNSM.cpp b/source/backend/CarlaStandaloneNSM.cpp index 797f5eb628..870f78fc33 100644 --- a/source/backend/CarlaStandaloneNSM.cpp +++ b/source/backend/CarlaStandaloneNSM.cpp @@ -1,19 +1,5 @@ -/* - * Carla Standalone - * Copyright (C) 2011-2022 Filipe Coelho - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * For a full copy of the GNU General Public License see the doc/GPL.txt file. - */ +// SPDX-FileCopyrightText: 2011-2024 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaHostImpl.hpp" @@ -318,9 +304,7 @@ class CarlaNSM fProjectPath = projectPath; fProjectPath += ".carxp"; - const String jfilename = String(CharPointer_UTF8(fProjectPath)); - - if (File(jfilename).existsAsFile()) + if (File(fProjectPath).existsAsFile()) carla_load_project(handle, fProjectPath); } diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index 2dce7e9dd5..100599b953 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -1220,8 +1220,7 @@ bool CarlaEngine::loadFile(const char* const filename) CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename"); carla_debug("CarlaEngine::loadFile(\"%s\")", filename); - const String jfilename = String(CharPointer_UTF8(filename)); - File file(jfilename); + File file(filename); CARLA_SAFE_ASSERT_RETURN_ERR(file.exists(), "Requested file does not exist or is not a readable"); CarlaString baseName(file.getFileNameWithoutExtension().toRawUTF8()); @@ -1392,8 +1391,7 @@ bool CarlaEngine::loadProject(const char* const filename, const bool setAsCurren CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename"); carla_debug("CarlaEngine::loadProject(\"%s\")", filename); - const String jfilename = String(CharPointer_UTF8(filename)); - const File file(jfilename); + const File file(filename); CARLA_SAFE_ASSERT_RETURN_ERR(file.existsAsFile(), "Requested file does not exist or is not a readable file"); if (setAsCurrentProject) @@ -1454,8 +1452,7 @@ bool CarlaEngine::saveProject(const char* const filename, const bool setAsCurren MemoryOutputStream out; saveProjectInternal(out); - const String jfilename = String(CharPointer_UTF8(filename)); - File file(jfilename); + File file(filename); if (file.replaceWithData(out.getData(), out.getDataSize())) return true; @@ -2604,7 +2601,7 @@ static String findBinaryInCustomPath(const char* const searchPath, const char* c jbinary = jbinary.substring(2).replaceCharacter('\\', '/'); #endif - String filename = File(jbinary).getFileName(); + String filename = File(jbinary.toRawUTF8()).getFileName(); int searchFlags = File::findFiles|File::ignoreHiddenFiles; @@ -2618,10 +2615,10 @@ static String findBinaryInCustomPath(const char* const searchPath, const char* c std::vector results; for (const String *it=searchPaths.begin(), *end=searchPaths.end(); it != end; ++it) { - const File path(*it); + const File path(it->toRawUTF8()); results.clear(); - path.findChildFiles(results, searchFlags, true, filename); + path.findChildFiles(results, searchFlags, true, filename.toRawUTF8()); if (!results.empty()) return results.front().getFullPathName(); @@ -2630,23 +2627,23 @@ static String findBinaryInCustomPath(const char* const searchPath, const char* c // try changing extension #if defined(CARLA_OS_MAC) if (filename.endsWithIgnoreCase(".dll") || filename.endsWithIgnoreCase(".so")) - filename = File(jbinary).getFileNameWithoutExtension() + ".dylib"; + filename = File(jbinary.toRawUTF8()).getFileNameWithoutExtension() + ".dylib"; #elif defined(CARLA_OS_WIN) if (filename.endsWithIgnoreCase(".dylib") || filename.endsWithIgnoreCase(".so")) - filename = File(jbinary).getFileNameWithoutExtension() + ".dll"; + filename = File(jbinary.toRawUTF8()).getFileNameWithoutExtension() + ".dll"; #else if (filename.endsWithIgnoreCase(".dll") || filename.endsWithIgnoreCase(".dylib")) - filename = File(jbinary).getFileNameWithoutExtension() + ".so"; + filename = File(jbinary.toRawUTF8()).getFileNameWithoutExtension() + ".so"; #endif else return String(); for (const String *it=searchPaths.begin(), *end=searchPaths.end(); it != end; ++it) { - const File path(*it); + const File path(it->toRawUTF8()); results.clear(); - path.findChildFiles(results, searchFlags, true, filename); + path.findChildFiles(results, searchFlags, true, filename.toRawUTF8()); if (!results.empty()) return results.front().getFullPathName(); diff --git a/source/backend/engine/CarlaEngineBridge.cpp b/source/backend/engine/CarlaEngineBridge.cpp index a34832f4b0..ce6d3c26ba 100644 --- a/source/backend/engine/CarlaEngineBridge.cpp +++ b/source/backend/engine/CarlaEngineBridge.cpp @@ -1,19 +1,5 @@ -/* - * Carla Plugin Host - * Copyright (C) 2011-2023 Filipe Coelho - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * For a full copy of the GNU General Public License see the doc/GPL.txt file. - */ +// SPDX-FileCopyrightText: 2011-2024 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #ifndef BUILD_BRIDGE # error This file should not be compiled if not building bridge @@ -947,7 +933,7 @@ class CarlaEngineBridge : public CarlaEngine, bigValueFilePath = bigValueFilePath.replaceSection(0, 1, "Z:\\").replace("/", "\\"); #endif - File bigValueFile(bigValueFilePath); + File bigValueFile(bigValueFilePath.toRawUTF8()); CARLA_SAFE_ASSERT_BREAK(bigValueFile.existsAsFile()); plugin->setCustomData(type.text, key.text, bigValueFile.loadFileAsString().toRawUTF8(), true); @@ -988,7 +974,7 @@ class CarlaEngineBridge : public CarlaEngine, chunkFilePath = chunkFilePath.replaceSection(0, 1, "Z:\\").replace("/", "\\"); #endif - File chunkFile(chunkFilePath); + File chunkFile(chunkFilePath.toRawUTF8()); CARLA_SAFE_ASSERT_BREAK(chunkFile.existsAsFile()); String chunkDataBase64(chunkFile.loadFileAsString()); @@ -1122,7 +1108,7 @@ class CarlaEngineBridge : public CarlaEngine, filePath += CARLA_OS_SEP_STR ".CarlaCustomData_"; filePath += fShmAudioPool.getFilenameSuffix(); - if (File(filePath).replaceWithText(cdata.value)) + if (File(filePath.toRawUTF8()).replaceWithText(cdata.value)) { const uint32_t ulength(static_cast(filePath.length())); @@ -1160,7 +1146,7 @@ class CarlaEngineBridge : public CarlaEngine, filePath += CARLA_OS_SEP_STR ".CarlaChunk_"; filePath += fShmAudioPool.getFilenameSuffix(); - if (File(filePath).replaceWithText(dataBase64.buffer())) + if (File(filePath.toRawUTF8()).replaceWithText(dataBase64.buffer())) { const uint32_t ulength(static_cast(filePath.length())); diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index d1485cf95c..6854395b5b 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -1,19 +1,5 @@ -/* - * Carla Plugin - * Copyright (C) 2011-2023 Filipe Coelho - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * For a full copy of the GNU General Public License see the doc/GPL.txt file. - */ +// SPDX-FileCopyrightText: 2011-2024 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaPluginInternal.hpp" #include "CarlaEngine.hpp" @@ -987,8 +973,7 @@ bool CarlaPlugin::saveStateToFile(const char* const filename) out << streamState; out << "\n"; - const String jfilename = String(CharPointer_UTF8(filename)); - File file(jfilename); + File file(filename); if (file.replaceWithData(out.getData(), out.getDataSize())) return true; @@ -1004,8 +989,7 @@ bool CarlaPlugin::loadStateFromFile(const char* const filename) CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false); carla_debug("CarlaPlugin::loadStateFromFile(\"%s\")", filename); - const String jfilename = String(CharPointer_UTF8(filename)); - File file(jfilename); + File file(filename); CARLA_SAFE_ASSERT_RETURN(file.existsAsFile(), false); XmlDocument xml(file); diff --git a/source/backend/plugin/CarlaPluginBridge.cpp b/source/backend/plugin/CarlaPluginBridge.cpp index 50c6214ba7..6dc5dab061 100644 --- a/source/backend/plugin/CarlaPluginBridge.cpp +++ b/source/backend/plugin/CarlaPluginBridge.cpp @@ -1,6 +1,6 @@ /* * Carla Plugin Bridge - * Copyright (C) 2011-2023 Filipe Coelho + * Copyright (C) 2011-2024 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -60,7 +60,7 @@ static String findWinePrefix(const String filename, const int recursionLimit = 1 const String path(filename.upToLastOccurrenceOf("/", false, false)); - if (File(path + "/dosdevices").isDirectory()) + if (File(String(path + "/dosdevices").toRawUTF8()).isDirectory()) return path; return findWinePrefix(path, recursionLimit-1); @@ -204,7 +204,7 @@ class CarlaPluginBridgeThread : public CarlaThread if (fBridgeBinary.endsWithIgnoreCase("64.exe") && options.wine.executable[0] == CARLA_OS_SEP - && File(wineCMD + "64").existsAsFile()) + && File(String(wineCMD + "64").toRawUTF8()).existsAsFile()) wineCMD += "64"; } else @@ -996,7 +996,7 @@ class CarlaPluginBridge : public CarlaPlugin filePath += CARLA_OS_SEP_STR ".CarlaCustomData_"; filePath += fShmAudioPool.getFilenameSuffix(); - if (File(filePath).replaceWithText(value)) + if (File(filePath.toRawUTF8()).replaceWithText(value)) { const uint32_t ulength = static_cast(filePath.length()); @@ -1034,7 +1034,7 @@ class CarlaPluginBridge : public CarlaPlugin filePath += CARLA_OS_SEP_STR ".CarlaChunk_"; filePath += fShmAudioPool.getFilenameSuffix(); - if (File(filePath).replaceWithText(dataBase64.buffer())) + if (File(filePath.toRawUTF8()).replaceWithText(dataBase64.buffer())) { const uint32_t ulength = static_cast(filePath.length()); @@ -2550,7 +2550,7 @@ class CarlaPluginBridge : public CarlaPlugin } #endif - const File bigValueFile(realBigValueFilePath); + const File bigValueFile(realBigValueFilePath.toRawUTF8()); CARLA_SAFE_ASSERT_BREAK(bigValueFile.existsAsFile()); CarlaPlugin::setCustomData(type.text, key.text, bigValueFile.loadFileAsString().toRawUTF8(), false); @@ -2591,7 +2591,7 @@ class CarlaPluginBridge : public CarlaPlugin } #endif - const File chunkFile(realChunkFilePath); + const File chunkFile(realChunkFilePath.toRawUTF8()); CARLA_SAFE_ASSERT_BREAK(chunkFile.existsAsFile()); fInfo.chunk = carla_getChunkFromBase64String(chunkFile.loadFileAsString().toRawUTF8()); @@ -3245,7 +3245,7 @@ class CarlaPluginBridge : public CarlaPlugin filePath += CARLA_OS_SEP_STR ".CarlaChunk_"; filePath += fShmAudioPool.getFilenameSuffix(); - if (File(filePath).replaceWithText(dataBase64.buffer())) + if (File(filePath.toRawUTF8()).replaceWithText(dataBase64.buffer())) { const uint32_t ulength(static_cast(filePath.length())); diff --git a/source/backend/plugin/CarlaPluginJSFX.cpp b/source/backend/plugin/CarlaPluginJSFX.cpp index f5e6f43fd1..8ac6d0c4bb 100644 --- a/source/backend/plugin/CarlaPluginJSFX.cpp +++ b/source/backend/plugin/CarlaPluginJSFX.cpp @@ -1,6 +1,6 @@ /* * Carla JSFX Plugin - * Copyright (C) 2021-2023 Filipe Coelho + * Copyright (C) 2021-2024 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -943,7 +943,7 @@ class CarlaPluginJSFX : public CarlaPlugin // find which engine search path we're in, and use this as the root for (int i = 0; i < splitPaths.size() && !fUnit; ++i) { - const File currentPath(splitPaths[i]); + const File currentPath(splitPaths[i].toRawUTF8()); if (file.isAChildOf(currentPath)) fUnit = CarlaJsfxUnit(currentPath, file); } @@ -957,10 +957,10 @@ class CarlaPluginJSFX : public CarlaPlugin // search a matching file in plugin paths for (int i = 0; i < splitPaths.size() && !fUnit; ++i) { - const File currentPath(splitPaths[i]); + const File currentPath(splitPaths[i].toRawUTF8()); const File currentFile = currentPath.getChildFile(CharPointer_UTF8(label)); const CarlaJsfxUnit currentUnit(currentPath, currentFile); - if (File(currentUnit.getFilePath()).existsAsFile()) + if (File(currentUnit.getFilePath().toRawUTF8()).existsAsFile()) fUnit = currentUnit; } } diff --git a/source/backend/utils/CachedPlugins.cpp b/source/backend/utils/CachedPlugins.cpp index c1ec6e83a3..f72530cd5b 100644 --- a/source/backend/utils/CachedPlugins.cpp +++ b/source/backend/utils/CachedPlugins.cpp @@ -79,7 +79,7 @@ static void findSFZs(const char* const sfzPaths) { std::vector results; - if (water::File(*it).findChildFiles(results, water::File::findFiles|water::File::ignoreHiddenFiles, true, "*.sfz") > 0) + if (water::File(it->toRawUTF8()).findChildFiles(results, water::File::findFiles|water::File::ignoreHiddenFiles, true, "*.sfz") > 0) { gSFZs.reserve(gSFZs.size() + results.size()); gSFZs.insert(gSFZs.end(), results.begin(), results.end()); @@ -107,7 +107,7 @@ static void findJSFXs(const char* const jsfxPaths) for (water::String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it) { std::vector results; - const water::File path(*it); + const water::File path(it->toRawUTF8()); if (path.findChildFiles(results, water::File::findFiles|water::File::ignoreHiddenFiles, true, "*") > 0) { diff --git a/source/backend/utils/PluginDiscovery.cpp b/source/backend/utils/PluginDiscovery.cpp index 78f34125f5..2ba24f5974 100644 --- a/source/backend/utils/PluginDiscovery.cpp +++ b/source/backend/utils/PluginDiscovery.cpp @@ -27,7 +27,7 @@ static water::String findWinePrefix(const water::String filename, const int recu const water::String path(filename.upToLastOccurrenceOf("/", false, false)); - if (water::File(path + "/dosdevices").isDirectory()) + if (water::File(water::String(path + "/dosdevices").toRawUTF8()).isDirectory()) return path; return findWinePrefix(path, recursionLimit-1); @@ -419,7 +419,7 @@ class CarlaPluginDiscovery : private CarlaPipeServer { helperTool = options.wine.executable.buffer(); - if (helperTool.isNotEmpty() && helperTool[0] == CARLA_OS_SEP && File(helperTool + "64").existsAsFile()) + if (helperTool.isNotEmpty() && helperTool[0] == CARLA_OS_SEP && File(String(helperTool + "64").toRawUTF8()).existsAsFile()) helperTool += "64"; } else @@ -606,7 +606,7 @@ static bool findDirectories(std::vector& files, const char* const p for (String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it) { - const File dir(*it); + const File dir(it->toRawUTF8()); std::vector results; if (dir.findChildFiles(results, File::findDirectories|File::ignoreHiddenFiles, true, wildcard) > 0) @@ -638,7 +638,7 @@ static bool findFiles(std::vector& files, for (String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it) { - const File dir(*it); + const File dir(it->toRawUTF8()); std::vector results; if (dir.findChildFiles(results, File::findFiles|File::ignoreHiddenFiles, true, wildcard) > 0) @@ -681,7 +681,7 @@ static bool findVST3s(std::vector& files, for (String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it) { - const File dir(*it); + const File dir(it->toRawUTF8()); std::vector results; if (dir.findChildFiles(results, flags|File::ignoreHiddenFiles, true, "*.vst3") > 0) diff --git a/source/bridges-plugin/CarlaBridgePlugin.cpp b/source/bridges-plugin/CarlaBridgePlugin.cpp index 843e118833..028c15811d 100644 --- a/source/bridges-plugin/CarlaBridgePlugin.cpp +++ b/source/bridges-plugin/CarlaBridgePlugin.cpp @@ -1,19 +1,5 @@ -/* - * Carla Bridge Plugin - * Copyright (C) 2012-2024 Filipe Coelho - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * For a full copy of the GNU General Public License see the doc/GPL.txt file. - */ +// SPDX-FileCopyrightText: 2011-2024 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #ifndef BUILD_BRIDGE # error This file should not be compiled if not building bridge @@ -215,7 +201,7 @@ class CarlaBridgePlugin if (! File::isAbsolutePath(gProjectFilename)) gProjectFilename = File::getCurrentWorkingDirectory().getChildFile(gProjectFilename).getFullPathName(); - if (File(gProjectFilename).existsAsFile()) + if (File(gProjectFilename.toRawUTF8()).existsAsFile()) { if (carla_load_plugin_state(gHostHandle, 0, gProjectFilename.toRawUTF8())) carla_stdout("Plugin state loaded successfully"); diff --git a/source/includes/CarlaNativePrograms.hpp b/source/includes/CarlaNativePrograms.hpp index 691a4ad1a8..23c930b42c 100644 --- a/source/includes/CarlaNativePrograms.hpp +++ b/source/includes/CarlaNativePrograms.hpp @@ -1,6 +1,6 @@ /* * Carla Native Plugin API (C++) - * Copyright (C) 2012-2022 Filipe Coelho + * Copyright (C) 2012-2024 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -64,7 +64,7 @@ struct NativePluginPresetManager { { std::vector results; - if (const uint count = File(*it).findChildFiles(results, File::findFiles|File::ignoreHiddenFiles, true, wildcard)) + if (const uint count = File(it->toRawUTF8()).findChildFiles(results, File::findFiles|File::ignoreHiddenFiles, true, wildcard)) { for (uint i=0; i + Copyright (C) 2017-2024 Filipe Coelho Permission is granted to use this software under the terms of the ISC license http://www.isc.org/downloads/software-support-policy/isc-license/ @@ -149,7 +149,7 @@ const File& DirectoryIterator::getFile() const float DirectoryIterator::getEstimatedProgress() const { if (totalNumFiles < 0) - totalNumFiles = File (path).getNumberOfChildFiles (File::findFilesAndDirectories); + totalNumFiles = File (path.toRawUTF8()).getNumberOfChildFiles (File::findFilesAndDirectories); if (totalNumFiles <= 0) return 0.0f; diff --git a/source/modules/water/files/File.cpp b/source/modules/water/files/File.cpp index 7a2a0ba5eb..6c900d9c09 100644 --- a/source/modules/water/files/File.cpp +++ b/source/modules/water/files/File.cpp @@ -3,7 +3,7 @@ This file is part of the Water library. Copyright (c) 2016 ROLI Ltd. - Copyright (C) 2017-2023 Filipe Coelho + Copyright (C) 2017-2024 Filipe Coelho Permission is granted to use this software under the terms of the ISC license http://www.isc.org/downloads/software-support-policy/isc-license/ @@ -57,8 +57,8 @@ File::File () noexcept { } -File::File (const String& fullPathName) - : fullPath (parseAbsolutePath (fullPathName)) +File::File (const char* const absolutePath) + : fullPath (parseAbsolutePath (absolutePath)) { } @@ -74,9 +74,9 @@ File::File (const File& other) { } -File& File::operator= (const String& newPath) +File& File::operator= (const char* const newAbsolutePath) { - fullPath = parseAbsolutePath (newPath); + fullPath = parseAbsolutePath (newAbsolutePath); return *this; } @@ -420,7 +420,7 @@ File File::getChildFile (StringRef relativePath) const CharPointer_UTF8 r = relativePath.text; if (isAbsolutePath (r)) - return File (String (r)); + return File (r); #ifdef CARLA_OS_WIN if (r.indexOf ((water_uchar) '/') >= 0) @@ -467,7 +467,7 @@ File File::getChildFile (StringRef relativePath) const path = addTrailingSeparator (path); path.appendCharPointer (r); - return File (path); + return File (path.toRawUTF8()); } File File::getSiblingFile (StringRef fileName) const @@ -572,16 +572,11 @@ String File::loadFileAsString() const : String(); } -void File::readLines (StringArray& destLines) const -{ - destLines.addLines (loadFileAsString()); -} - //============================================================================== uint File::findChildFiles (std::vector& results, const int whatToLookFor, const bool searchRecursively, - const String& wildCardPattern) const + const char* const wildCardPattern) const { uint total = 0; @@ -594,7 +589,7 @@ uint File::findChildFiles (std::vector& results, return total; } -uint File::getNumberOfChildFiles (const int whatToLookFor, const String& wildCardPattern) const +uint File::getNumberOfChildFiles (const int whatToLookFor, const char* const wildCardPattern) const { uint total = 0; @@ -1443,7 +1438,7 @@ File water_getExecutableFile() for (int i=paths.size(); --i>=0;) { - const File filepath (File (paths[i]).getChildFile (filename)); + const File filepath (File (paths[i].toRawUTF8()).getChildFile (filename)); if (filepath.existsAsFile()) return filepath.getFullPathName(); @@ -1457,7 +1452,7 @@ File water_getExecutableFile() }; static String filename (DLAddrReader::getFilename()); - return filename; + return filename.toRawUTF8(); } #ifdef CARLA_OS_MAC @@ -1511,9 +1506,9 @@ File File::getSpecialLocation (const SpecialLocationType type) case tempDirectory: { - File tmp ("~/Library/Caches/" + water_getExecutableFile().getFileNameWithoutExtension()); + File tmp (String("~/Library/Caches/" + water_getExecutableFile().getFileNameWithoutExtension()).toRawUTF8()); tmp.createDirectory(); - return File (tmp.getFullPathName()); + return File (tmp.getFullPathName().toRawUTF8()); } case currentExecutableFile: @@ -1522,11 +1517,10 @@ File File::getSpecialLocation (const SpecialLocationType type) case hostApplicationPath: { unsigned int size = 8192; - HeapBlock buffer; - buffer.calloc (size + 8); - - _NSGetExecutablePath (buffer.getData(), &size); - return File (String::fromUTF8 (buffer, (int) size)); + char* const buffer = new char[size + 8]; + _NSGetExecutablePath (buffer, &size); + buffer[size] = 0; + return File (buffer); } default: @@ -1535,7 +1529,7 @@ File File::getSpecialLocation (const SpecialLocationType type) } if (resultPath.isNotEmpty()) - return File (resultPath.convertToPrecomposedUnicode()); + return File (resultPath.convertToPrecomposedUnicode().toRawUTF8()); return File(); } diff --git a/source/modules/water/files/File.h b/source/modules/water/files/File.h index 5b77c86775..282a25b76e 100644 --- a/source/modules/water/files/File.h +++ b/source/modules/water/files/File.h @@ -3,7 +3,7 @@ This file is part of the Water library. Copyright (c) 2016 ROLI Ltd. - Copyright (C) 2017-2023 Filipe Coelho + Copyright (C) 2017-2024 Filipe Coelho Permission is granted to use this software under the terms of the ISC license http://www.isc.org/downloads/software-support-policy/isc-license/ @@ -26,7 +26,6 @@ #ifndef WATER_FILE_H_INCLUDED #define WATER_FILE_H_INCLUDED -#include "../containers/Array.h" #include "../misc/Result.h" #include "../text/String.h" @@ -69,7 +68,7 @@ class File On the Mac/Linux, the path can include "~" notation for referring to user home directories. */ - File (const String& absolutePath); + File (const char* absolutePath); /** Creates a copy of another file object. */ File (const File&); @@ -87,7 +86,7 @@ class File On the Mac/Linux, the path can include "~" notation for referring to user home directories. */ - File& operator= (const String& newAbsolutePath); + File& operator= (const char* newAbsolutePath); /** Copies from another file object. */ File& operator= (const File& otherFile); @@ -469,7 +468,7 @@ class File Assuming that this file is a directory, this method will search it for either files or subdirectories whose names match a filename pattern. - @param results an array to which File objects will be added for the + @param results an vector to which File objects will be added for the files that the search comes up with @param whatToLookFor a value from the TypesOfFileToFind enum, specifying whether to return files, directories, or both. If the ignoreHiddenFiles flag @@ -484,7 +483,7 @@ class File uint findChildFiles (std::vector& results, int whatToLookFor, bool searchRecursively, - const String& wildCardPattern = "*") const; + const char* wildCardPattern = "*") const; /** Searches inside a directory and counts how many files match a wildcard pattern. @@ -503,7 +502,7 @@ class File @see findChildFiles, DirectoryIterator */ uint getNumberOfChildFiles (int whatToLookFor, - const String& wildCardPattern = "*") const; + const char* wildCardPattern = "*") const; /** Returns true if this file is a directory that contains one or more subdirectories. @see isDirectory, findChildFiles @@ -553,11 +552,6 @@ class File */ String loadFileAsString() const; - /** Reads the contents of this file as text and splits it into lines, which are - appended to the given StringArray. - */ - void readLines (StringArray& destLines) const; - //============================================================================== /** Appends a block of binary data to the end of the file. diff --git a/source/native-plugins/midi-file.cpp b/source/native-plugins/midi-file.cpp index 1fa5eb8cc9..f534177279 100644 --- a/source/native-plugins/midi-file.cpp +++ b/source/native-plugins/midi-file.cpp @@ -1,6 +1,6 @@ /* * Carla Native Plugins - * Copyright (C) 2012-2022 Filipe Coelho + * Copyright (C) 2012-2024 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -365,8 +365,7 @@ class MidiFilePlugin : public NativePluginWithMidiPrograms, using namespace water; - const String jfilename = String(CharPointer_UTF8(filename)); - File file(jfilename); + File file(filename); if (! file.existsAsFile()) return; diff --git a/source/utils/CarlaDssiUtils.cpp b/source/utils/CarlaDssiUtils.cpp index 77ceffb7d7..cee62ac39b 100644 --- a/source/utils/CarlaDssiUtils.cpp +++ b/source/utils/CarlaDssiUtils.cpp @@ -1,6 +1,6 @@ /* * Carla DSSI utils - * Copyright (C) 2013-2018 Filipe Coelho + * Copyright (C) 2013-2024 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -32,7 +32,7 @@ const char* find_dssi_ui(const char* const filename, const char* const label) no water::String pluginDir(water::String(filename).upToLastOccurrenceOf(".", false, false)); water::String checkLabel(label); - water::String checkSName(water::File(pluginDir).getFileName()); + water::String checkSName(water::File(pluginDir.toRawUTF8()).getFileName()); if (checkSName.endsWithIgnoreCase("dssi")) { @@ -47,9 +47,8 @@ const char* find_dssi_ui(const char* const filename, const char* const label) no std::vector results; - if (const uint count = water::File(pluginDir).findChildFiles(results, - water::File::findFiles|water::File::ignoreHiddenFiles, - false)) + if (const uint count = water::File(pluginDir.toRawUTF8()).findChildFiles( + results, water::File::findFiles|water::File::ignoreHiddenFiles, false)) { for (uint i=0; i