OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
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
23 namespace juce
24{
25
26#if ! DOXYGEN && (JUCE_MAC || JUCE_IOS)
27 using OSType = unsigned int;
28#endif
29
30//==============================================================================
44 class JUCE_API File final
45{
46 public:
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
435 String getVersion() const;
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 //==============================================================================
563 enum TypesOfFileToFind
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
807 String getVolumeLabel() const;
808
812 int getVolumeSerialNumber() const;
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 //==============================================================================
866 enum SpecialLocationType
867 {
869 userHomeDirectory,
870
875 userDocumentsDirectory,
876
878 userDesktopDirectory,
879
881 userMusicDirectory,
882
884 userMoviesDirectory,
885
887 userPicturesDirectory,
888
895 userApplicationDataDirectory,
896
907 commonApplicationDataDirectory,
908
914 commonDocumentsDirectory,
915
919 tempDirectory,
920
932 currentExecutableFile,
933
942 currentApplicationFile,
943
949 invokedExecutableFile,
950
952 hostApplicationPath,
953
954 #if JUCE_WINDOWS || DOXYGEN
956 windowsSystemDirectory,
957 #endif
958
963 globalApplicationsDirectory,
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 //==============================================================================
998 static File getCurrentWorkingDirectory();
999
1007 bool setAsCurrentWorkingDirectory() const;
1008
1009 //==============================================================================
1013 static juce_wchar getSeparatorChar();
1014
1018 static StringRef getSeparatorString();
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
1082 String getNativeLinkedTarget() const;
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 //==============================================================================
1121 struct NaturalFileComparator
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
1151 private:
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
juce::Array
Definition juce_Array.h:56
juce::File
Definition juce_File.h:45
juce::File::getVolumeSerialNumber
int getVolumeSerialNumber() const
juce::File::isSymbolicLink
bool isSymbolicLink() const
juce::File::isHidden
bool isHidden() const
juce::File::isOnHardDisk
bool isOnHardDisk() const
juce::File::isDirectory
bool isDirectory() const
juce::File::findFileSystemRoots
static void findFileSystemRoots(Array< File > &results)
juce::File::setAsCurrentWorkingDirectory
bool setAsCurrentWorkingDirectory() const
juce::File::isOnCDRomDrive
bool isOnCDRomDrive() const
juce::File::isOnRemovableDrive
bool isOnRemovableDrive() const
juce::File::getVolumeTotalSize
int64 getVolumeTotalSize() const
juce::File::getBytesFreeOnVolume
int64 getBytesFreeOnVolume() const
juce::File::hasWriteAccess
bool hasWriteAccess() const
juce::File::getSpecialLocation
static File JUCE_CALLTYPE getSpecialLocation(const SpecialLocationType type)
juce::File::getFullPathName
const String & getFullPathName() const noexcept
Definition juce_File.h:153
juce::File::~File
~File()=default
juce::File::revealToUser
void revealToUser() const
juce::File::SpecialLocationType
SpecialLocationType
Definition juce_File.h:867
juce::File::userMoviesDirectory
@ userMoviesDirectory
Definition juce_File.h:884
juce::File::userMusicDirectory
@ userMusicDirectory
Definition juce_File.h:881
juce::File::tempDirectory
@ tempDirectory
Definition juce_File.h:919
juce::File::globalApplicationsDirectory
@ globalApplicationsDirectory
Definition juce_File.h:963
juce::File::userDocumentsDirectory
@ userDocumentsDirectory
Definition juce_File.h:875
juce::File::currentApplicationFile
@ currentApplicationFile
Definition juce_File.h:942
juce::File::invokedExecutableFile
@ invokedExecutableFile
Definition juce_File.h:949
juce::File::commonDocumentsDirectory
@ commonDocumentsDirectory
Definition juce_File.h:914
juce::File::userApplicationDataDirectory
@ userApplicationDataDirectory
Definition juce_File.h:895
juce::File::userPicturesDirectory
@ userPicturesDirectory
Definition juce_File.h:887
juce::File::commonApplicationDataDirectory
@ commonApplicationDataDirectory
Definition juce_File.h:907
juce::File::userDesktopDirectory
@ userDesktopDirectory
Definition juce_File.h:878
juce::File::hostApplicationPath
@ hostApplicationPath
Definition juce_File.h:952
juce::File::currentExecutableFile
@ currentExecutableFile
Definition juce_File.h:932
juce::File::userHomeDirectory
@ userHomeDirectory
Definition juce_File.h:869
juce::File::TypesOfFileToFind
TypesOfFileToFind
Definition juce_File.h:564
juce::File::getSeparatorChar
static juce_wchar getSeparatorChar()
juce::File::FollowSymlinks
FollowSymlinks
Definition juce_File.h:572
juce::File::hasReadAccess
bool hasReadAccess() const
juce::File::moveToTrash
bool moveToTrash() const
juce::File::getVolumeLabel
String getVolumeLabel() const
juce::File::getFileIdentifier
uint64 getFileIdentifier() const
juce::File::File
File()=default
juce::File::deleteFile
bool deleteFile() const
juce::File::getVersion
String getVersion() const
juce::File::getNativeLinkedTarget
String getNativeLinkedTarget() const
juce::File::getCurrentWorkingDirectory
static File getCurrentWorkingDirectory()
juce::File::getSeparatorString
static StringRef getSeparatorString()
juce::MemoryBlock
Definition juce_MemoryBlock.h:33
juce::Result
Definition juce_Result.h:57
juce::StringArray
Definition juce_StringArray.h:35
juce::StringRef
Definition juce_StringRef.h:62
juce::String
Definition juce_String.h:53
juce::String::compareNatural
int compareNatural(StringRef other, bool isCaseSensitive=false) const noexcept
Definition juce_String.cpp:700
juce::Time
Definition juce_Time.h:37
juce::File::NaturalFileComparator
Definition juce_File.h:1122