OpenShot Audio Library | OpenShotAudio 0.4.0
juce_File.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26#if ! DOXYGEN && (JUCE_MAC || JUCE_IOS)
27 using OSType = unsigned int;
28#endif
29
30//==============================================================================
44class JUCE_API File final
45{
46public:
47 //==============================================================================
55 File() = default;
56
67 File (const String& absolutePath);
68
70 File (const File&);
71
73 ~File() = default;
74
85 File& operator= (const String& newAbsolutePath);
86
88 File& operator= (const File& otherFile);
89
91 File (File&&) noexcept;
92
94 File& operator= (File&&) noexcept;
95
96 //==============================================================================
102 bool exists() const;
103
110 bool existsAsFile() const;
111
118 bool isDirectory() const;
119
126 bool isRoot() const;
127
132 int64 getSize() const;
133
139 static String descriptionOfSizeInBytes (int64 bytes);
140
141 //==============================================================================
153 const String& getFullPathName() const noexcept { return fullPath; }
154
168 String getFileName() const;
169
185 String getRelativePathFrom (const File& directoryToBeRelativeTo) const;
186
187 //==============================================================================
196 String getFileExtension() const;
197
209 bool hasFileExtension (StringRef extensionToTest) const;
210
221 File withFileExtension (StringRef newExtension) const;
222
229 String getFileNameWithoutExtension() const;
230
231 //==============================================================================
237 int hashCode() const;
238
244 int64 hashCode64() const;
245
246 //==============================================================================
261 File getChildFile (StringRef relativeOrAbsolutePath) const;
262
269 File getSiblingFile (StringRef siblingFileName) const;
270
271 //==============================================================================
279 File getParentDirectory() const;
280
290 bool isAChildOf (const File& potentialParentDirectory) const;
291
292 //==============================================================================
310 File getNonexistentChildFile (const String& prefix,
311 const String& suffix,
312 bool putNumbersInBrackets = true) const;
313
323 File getNonexistentSibling (bool putNumbersInBrackets = true) const;
324
325 //==============================================================================
327 bool operator== (const File&) const;
329 bool operator!= (const File&) const;
331 bool operator< (const File&) const;
333 bool operator> (const File&) const;
334
335 //==============================================================================
343 bool hasWriteAccess() const;
344
349 bool hasReadAccess() const;
350
360 bool setReadOnly (bool shouldBeReadOnly,
361 bool applyRecursively = false) const;
362
368 bool setExecutePermission (bool shouldBeExecutable) const;
369
373 bool isHidden() const;
374
381 uint64 getFileIdentifier() const;
382
383 //==============================================================================
389 Time getLastModificationTime() const;
390
396 Time getLastAccessTime() const;
397
403 Time getCreationTime() const;
404
411 bool setLastModificationTime (Time newTime) const;
412
419 bool setLastAccessTime (Time newTime) const;
420
427 bool setCreationTime (Time newTime) const;
428
436
437 //==============================================================================
452 Result create() const;
453
463 Result createDirectory() const;
464
477 bool deleteFile() const;
478
491 bool deleteRecursively (bool followSymlinks = false) const;
492
499 bool moveToTrash() const;
500
519 bool moveFileTo (const File& targetLocation) const;
520
531 bool copyFileTo (const File& targetLocation) const;
532
543 bool replaceFileIn (const File& targetLocation) const;
544
558 bool copyDirectoryTo (const File& newDirectory) const;
559
560 //==============================================================================
564 {
565 findDirectories = 1,
566 findFiles = 2,
567 findFilesAndDirectories = 3,
568 ignoreHiddenFiles = 4
569 };
570
571 enum class FollowSymlinks
572 {
574 no,
575
579 noCycles,
580
585 yes
586 };
587
605 Array<File> findChildFiles (int whatToLookFor,
606 bool searchRecursively,
607 const String& wildCardPattern = "*",
608 FollowSymlinks followSymlinks = FollowSymlinks::yes) const;
609
615 int findChildFiles (Array<File>& results, int whatToLookFor,
616 bool searchRecursively, const String& wildCardPattern = "*",
617 FollowSymlinks followSymlinks = FollowSymlinks::yes) const;
618
636 int getNumberOfChildFiles (int whatToLookFor,
637 const String& wildCardPattern = "*") const;
638
642 bool containsSubDirectories() const;
643
644 //==============================================================================
662 std::unique_ptr<FileInputStream> createInputStream() const;
663
695 std::unique_ptr<FileOutputStream> createOutputStream (size_t bufferSize = 0x8000) const;
696
697 //==============================================================================
708 bool loadFileAsData (MemoryBlock& result) const;
709
717 String loadFileAsString() const;
718
722 void readLines (StringArray& destLines) const;
723
724 //==============================================================================
731 bool appendData (const void* dataToAppend,
732 size_t numberOfBytes) const;
733
748 bool replaceWithData (const void* dataToWrite,
749 size_t numberOfBytes) const;
750
764 bool appendText (const String& textToAppend,
765 bool asUnicode = false,
766 bool writeUnicodeHeaderBytes = false,
767 const char* lineEndings = "\r\n") const;
768
785 bool replaceWithText (const String& textToWrite,
786 bool asUnicode = false,
787 bool writeUnicodeHeaderBytes = false,
788 const char* lineEndings = "\r\n") const;
789
793 bool hasIdenticalContentTo (const File& other) const;
794
795 //==============================================================================
802 static void findFileSystemRoots (Array<File>& results);
803
808
813
819 int64 getBytesFreeOnVolume() const;
820
826 int64 getVolumeTotalSize() const;
827
829 bool isOnCDRomDrive() const;
830
836 bool isOnHardDisk() const;
837
842 bool isOnRemovableDrive() const;
843
844 //==============================================================================
856 bool startAsProcess (const String& parameters = String()) const;
857
861 void revealToUser() const;
862
863 //==============================================================================
867 {
870
876
879
882
885
888
896
908
915
920
933
943
950
953
954 #if JUCE_WINDOWS || DOXYGEN
956 windowsSystemDirectory,
957 #endif
958
964
965 #if JUCE_WINDOWS || DOXYGEN
973 globalApplicationsDirectoryX86,
974
976 windowsLocalAppData
977 #endif
978 };
979
985 static File JUCE_CALLTYPE getSpecialLocation (const SpecialLocationType type);
986
987 //==============================================================================
992 static File createTempFile (StringRef fileNameEnding);
993
994 //==============================================================================
999
1008
1009 //==============================================================================
1013 static juce_wchar getSeparatorChar();
1014
1019
1020 //==============================================================================
1032 static String createLegalFileName (const String& fileNameToFix);
1033
1041 static String createLegalPathName (const String& pathNameToFix);
1042
1044 static bool areFileNamesCaseSensitive();
1045
1047 static bool isAbsolutePath (StringRef path);
1048
1054 static File createFileWithoutCheckingPath (const String& absolutePath) noexcept;
1055
1057 static String addTrailingSeparator (const String& path);
1058
1059 //==============================================================================
1061 bool createSymbolicLink (const File& linkFileToCreate, bool overwriteExisting) const;
1062
1064 bool isSymbolicLink() const;
1065
1069 File getLinkedTarget() const;
1070
1076 static bool createSymbolicLink (const File& linkFileToCreate,
1077 const String& nativePathOfTarget,
1078 bool overwriteExisting);
1079
1083
1084 #if JUCE_WINDOWS || DOXYGEN
1086 bool createShortcut (const String& description, const File& linkFileToCreate) const;
1087
1089 bool isShortcut() const;
1090 #else
1091
1092 #endif
1093
1094 //==============================================================================
1095 #if JUCE_MAC || JUCE_IOS || DOXYGEN
1097 OSType getMacOSType() const;
1098
1100 bool isBundle() const;
1101 #endif
1102
1103 #if JUCE_MAC || DOXYGEN
1105 void addToDock() const;
1106 #endif
1107
1108 #if JUCE_MAC || JUCE_IOS
1116 static File getContainerForSecurityApplicationGroupIdentifier (const String& appGroup);
1117 #endif
1118
1119 //==============================================================================
1122 {
1123 NaturalFileComparator (bool shouldPutFoldersFirst) noexcept : foldersFirst (shouldPutFoldersFirst) {}
1124
1125 int compareElements (const File& firstFile, const File& secondFile) const
1126 {
1127 if (foldersFirst && (firstFile.isDirectory() != secondFile.isDirectory()))
1128 return firstFile.isDirectory() ? -1 : 1;
1129
1130 #if NAMES_ARE_CASE_SENSITIVE
1131 return firstFile.getFullPathName().compareNatural (secondFile.getFullPathName(), true);
1132 #else
1133 return firstFile.getFullPathName().compareNatural (secondFile.getFullPathName(), false);
1134 #endif
1135 }
1136
1137 bool foldersFirst;
1138 };
1139
1140 #if JUCE_ALLOW_STATIC_NULL_VARIABLES && ! defined (DOXYGEN)
1141 /* These static objects are deprecated because it's too easy to accidentally use them indirectly
1142 during a static constructor, which leads to very obscure order-of-initialisation bugs.
1143 Use File::getSeparatorChar() and File::getSeparatorString(), and instead of File::nonexistent,
1144 just use File() or {}.
1145 */
1146 [[deprecated]] static const juce_wchar separator;
1147 [[deprecated]] static const StringRef separatorString;
1148 [[deprecated]] static const File nonexistent;
1149 #endif
1150
1151private:
1152 //==============================================================================
1153 String fullPath;
1154
1155 static String parseAbsolutePath (const String&);
1156 String getPathUpToLastSlash() const;
1157 bool isNonEmptyDirectory() const;
1158
1159 Result createDirectoryInternal (const String&) const;
1160 bool copyInternal (const File&) const;
1161 bool moveInternal (const File&) const;
1162 bool replaceInternal (const File&) const;
1163 bool setFileTimesInternal (int64 m, int64 a, int64 c) const;
1164 void getFileTimesInternal (int64& m, int64& a, int64& c) const;
1165 bool setFileReadOnlyInternal (bool) const;
1166 bool setFileExecutableInternal (bool) const;
1167};
1168
1169} // namespace juce
int getVolumeSerialNumber() const
bool isSymbolicLink() const
bool isHidden() const
bool isOnHardDisk() const
bool isDirectory() const
static void findFileSystemRoots(Array< File > &results)
bool setAsCurrentWorkingDirectory() const
bool isOnCDRomDrive() const
bool isOnRemovableDrive() const
int64 getVolumeTotalSize() const
int64 getBytesFreeOnVolume() const
bool hasWriteAccess() const
static File JUCE_CALLTYPE getSpecialLocation(const SpecialLocationType type)
const String & getFullPathName() const noexcept
Definition: juce_File.h:153
~File()=default
void revealToUser() const
SpecialLocationType
Definition: juce_File.h:867
@ userMoviesDirectory
Definition: juce_File.h:884
@ userMusicDirectory
Definition: juce_File.h:881
@ tempDirectory
Definition: juce_File.h:919
@ globalApplicationsDirectory
Definition: juce_File.h:963
@ userDocumentsDirectory
Definition: juce_File.h:875
@ currentApplicationFile
Definition: juce_File.h:942
@ invokedExecutableFile
Definition: juce_File.h:949
@ commonDocumentsDirectory
Definition: juce_File.h:914
@ userApplicationDataDirectory
Definition: juce_File.h:895
@ userPicturesDirectory
Definition: juce_File.h:887
@ commonApplicationDataDirectory
Definition: juce_File.h:907
@ userDesktopDirectory
Definition: juce_File.h:878
@ hostApplicationPath
Definition: juce_File.h:952
@ currentExecutableFile
Definition: juce_File.h:932
@ userHomeDirectory
Definition: juce_File.h:869
static juce_wchar getSeparatorChar()
bool hasReadAccess() const
bool moveToTrash() const
String getVolumeLabel() const
uint64 getFileIdentifier() const
File()=default
bool deleteFile() const
String getVersion() const
String getNativeLinkedTarget() const
static File getCurrentWorkingDirectory()
static StringRef getSeparatorString()
int compareNatural(StringRef other, bool isCaseSensitive=false) const noexcept