Skip to content

Commit

Permalink
Clean water File(const String&) usage
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Apr 27, 2024
1 parent a580473 commit 51186c9
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 158 deletions.
22 changes: 3 additions & 19 deletions source/backend/CarlaStandaloneNSM.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
/*
* Carla Standalone
* Copyright (C) 2011-2022 Filipe Coelho <falktx@falktx.com>
*
* 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 <falktx@falktx.com>
// SPDX-License-Identifier: GPL-2.0-or-later

#include "CarlaHostImpl.hpp"

Expand Down Expand Up @@ -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);
}

Expand Down
25 changes: 11 additions & 14 deletions source/backend/engine/CarlaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -2618,10 +2615,10 @@ static String findBinaryInCustomPath(const char* const searchPath, const char* c
std::vector<File> 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();
Expand All @@ -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();
Expand Down
26 changes: 6 additions & 20 deletions source/backend/engine/CarlaEngineBridge.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
/*
* Carla Plugin Host
* Copyright (C) 2011-2023 Filipe Coelho <falktx@falktx.com>
*
* 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 <falktx@falktx.com>
// SPDX-License-Identifier: GPL-2.0-or-later

#ifndef BUILD_BRIDGE
# error This file should not be compiled if not building bridge
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<uint32_t>(filePath.length()));

Expand Down Expand Up @@ -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<uint32_t>(filePath.length()));

Expand Down
24 changes: 4 additions & 20 deletions source/backend/plugin/CarlaPlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
/*
* Carla Plugin
* Copyright (C) 2011-2023 Filipe Coelho <falktx@falktx.com>
*
* 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 <falktx@falktx.com>
// SPDX-License-Identifier: GPL-2.0-or-later

#include "CarlaPluginInternal.hpp"
#include "CarlaEngine.hpp"
Expand Down Expand Up @@ -987,8 +973,7 @@ bool CarlaPlugin::saveStateToFile(const char* const filename)
out << streamState;
out << "</CARLA-PRESET>\n";

const String jfilename = String(CharPointer_UTF8(filename));
File file(jfilename);
File file(filename);

if (file.replaceWithData(out.getData(), out.getDataSize()))
return true;
Expand All @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions source/backend/plugin/CarlaPluginBridge.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Carla Plugin Bridge
* Copyright (C) 2011-2023 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2011-2024 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<uint32_t>(filePath.length());

Expand Down Expand Up @@ -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<uint32_t>(filePath.length());

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<uint32_t>(filePath.length()));

Expand Down
8 changes: 4 additions & 4 deletions source/backend/plugin/CarlaPluginJSFX.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Carla JSFX Plugin
* Copyright (C) 2021-2023 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2021-2024 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/backend/utils/CachedPlugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void findSFZs(const char* const sfzPaths)
{
std::vector<water::File> 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());
Expand Down Expand Up @@ -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<water::File> results;
const water::File path(*it);
const water::File path(it->toRawUTF8());

if (path.findChildFiles(results, water::File::findFiles|water::File::ignoreHiddenFiles, true, "*") > 0)
{
Expand Down
10 changes: 5 additions & 5 deletions source/backend/utils/PluginDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -606,7 +606,7 @@ static bool findDirectories(std::vector<water::File>& 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<File> results;

if (dir.findChildFiles(results, File::findDirectories|File::ignoreHiddenFiles, true, wildcard) > 0)
Expand Down Expand Up @@ -638,7 +638,7 @@ static bool findFiles(std::vector<water::File>& files,

for (String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it)
{
const File dir(*it);
const File dir(it->toRawUTF8());
std::vector<File> results;

if (dir.findChildFiles(results, File::findFiles|File::ignoreHiddenFiles, true, wildcard) > 0)
Expand Down Expand Up @@ -681,7 +681,7 @@ static bool findVST3s(std::vector<water::File>& files,

for (String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it)
{
const File dir(*it);
const File dir(it->toRawUTF8());
std::vector<File> results;

if (dir.findChildFiles(results, flags|File::ignoreHiddenFiles, true, "*.vst3") > 0)
Expand Down

0 comments on commit 51186c9

Please sign in to comment.