tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_FileUtilities.cpp
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
14juce::File getNonExistentSiblingWithIncrementedNumberSuffix (const juce::File& file, bool addHashSymbol)
15{
16 if (! file.existsAsFile())
17 return file;
18
19 auto name = juce::File::createLegalFileName (file.getFileNameWithoutExtension());
20
21 int drop = 0;
22 bool foundDigit = false;
23 bool foundHash = ! addHashSymbol;
24
25 for (int i = name.length(); --i >= 0;)
26 {
27 if (name[i] == '#' && foundDigit)
28 foundHash = true;
29 else if (juce::String ("0123456789").containsChar (name[i]))
30 foundDigit = true;
31 else
32 break;
33
34 drop++;
35 }
36
37 bool inForm = foundDigit && foundHash;
38 int number = inForm ? name.getTrailingIntValue() : 0;
39 name = inForm ? name.dropLastCharacters(drop).trimEnd() : name;
40
41 juce::File newFileName;
42
43 do
44 {
45 number++;
46
47 auto nameWithNumber = name + (addHashSymbol ? " #" : " ")
48 + juce::String (number) + file.getFileExtension();
49
50 newFileName = file.getParentDirectory()
51 .getChildFile (nameWithNumber);
52
53 } while (newFileName.exists());
54
55 return newFileName;
56}
57
58//==============================================================================
59bool isMidiFile (const juce::File& f) { return f.hasFileExtension ("mid;rmi;rmid;midi"); }
60bool isTracktionEditFile (const juce::File& f) { return f.hasFileExtension (editFileSuffix) || f.hasFileExtension (legacyEditFileSuffix); }
61bool isTracktionArchiveFile (const juce::File& f) { return f.hasFileExtension (archiveFileSuffix); }
62bool isTracktionProjectFile (const juce::File& f) { return f.hasFileExtension (projectFileSuffix); }
63bool isTracktionPresetFile (const juce::File& f) { return f.hasFileExtension (presetFileSuffix); }
64
65//==============================================================================
66FileDragList::Ptr FileDragList::getFromDrag (const juce::DragAndDropTarget::SourceDetails& s)
67{
68 return dynamic_cast<FileDragList*> (s.description.getObject());
69}
70
71juce::var FileDragList::create (const juce::Array<juce::File>& files, PreferredLayout preferredLayout)
72{
73 FileDragList* l = new FileDragList();
74 l->preferredLayout = preferredLayout;
75 l->files = files;
76 return l;
77}
78
79juce::var FileDragList::create (const juce::File& file, PreferredLayout peferredLayout)
80{
82 files.add (file);
83 return create (files, peferredLayout);
84}
85
86}} // namespace tracktion { inline namespace engine
void add(const ElementType &newElement)
static String createLegalFileName(const String &fileNameToFix)
bool hasFileExtension(StringRef extensionToTest) const
bool exists() const
bool containsChar(juce_wchar character) const noexcept