OpenShot Audio Library | OpenShotAudio: juce_File.h Source File

OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
juce_File.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
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//==============================================================================
40 class JUCE_API File final
41{
42public:
43 //==============================================================================
51 File() = default;
52
63 File (const String& absolutePath);
64
66 File (const File&);
67
69 ~File() = default;
70
81 File& operator= (const String& newAbsolutePath);
82
84 File& operator= (const File& otherFile);
85
87 File (File&&) noexcept;
88
90 File& operator= (File&&) noexcept;
91
92 //==============================================================================
98 bool exists() const;
99
106 bool existsAsFile() const;
107
114 bool isDirectory() const;
115
122 bool isRoot() const;
123
128 int64 getSize() const;
129
135 static String descriptionOfSizeInBytes (int64 bytes);
136
137 //==============================================================================
149 const String& getFullPathName() const noexcept { return fullPath; }
150
164 String getFileName() const;
165
181 String getRelativePathFrom (const File& directoryToBeRelativeTo) const;
182
183 //==============================================================================
192 String getFileExtension() const;
193
205 bool hasFileExtension (StringRef extensionToTest) const;
206
217 File withFileExtension (StringRef newExtension) const;
218
225 String getFileNameWithoutExtension() const;
226
227 //==============================================================================
233 int hashCode() const;
234
240 int64 hashCode64() const;
241
242 //==============================================================================
257 File getChildFile (StringRef relativeOrAbsolutePath) const;
258
265 File getSiblingFile (StringRef siblingFileName) const;
266
267 //==============================================================================
275 File getParentDirectory() const;
276
286 bool isAChildOf (const File& potentialParentDirectory) const;
287
288 //==============================================================================
306 File getNonexistentChildFile (const String& prefix,
307 const String& suffix,
308 bool putNumbersInBrackets = true) const;
309
319 File getNonexistentSibling (bool putNumbersInBrackets = true) const;
320
321 //==============================================================================
323 bool operator== (const File&) const;
325 bool operator!= (const File&) const;
327 bool operator< (const File&) const;
329 bool operator> (const File&) const;
330
331 //==============================================================================
339 bool hasWriteAccess() const;
340
350 bool setReadOnly (bool shouldBeReadOnly,
351 bool applyRecursively = false) const;
352
358 bool setExecutePermission (bool shouldBeExecutable) const;
359
363 bool isHidden() const;
364
371 uint64 getFileIdentifier() const;
372
373 //==============================================================================
379 Time getLastModificationTime() const;
380
386 Time getLastAccessTime() const;
387
393 Time getCreationTime() const;
394
401 bool setLastModificationTime (Time newTime) const;
402
409 bool setLastAccessTime (Time newTime) const;
410
417 bool setCreationTime (Time newTime) const;
418
425 String getVersion() const;
426
427 //==============================================================================
442 Result create() const;
443
453 Result createDirectory() const;
454
467 bool deleteFile() const;
468
481 bool deleteRecursively (bool followSymlinks = false) const;
482
489 bool moveToTrash() const;
490
505 bool moveFileTo (const File& targetLocation) const;
506
515 bool copyFileTo (const File& targetLocation) const;
516
527 bool replaceFileIn (const File& targetLocation) const;
528
542 bool copyDirectoryTo (const File& newDirectory) const;
543
544 //==============================================================================
547 enum TypesOfFileToFind
548 {
549 findDirectories = 1,
550 findFiles = 2,
551 findFilesAndDirectories = 3,
552 ignoreHiddenFiles = 4
553 };
554
571 Array<File> findChildFiles (int whatToLookFor,
572 bool searchRecursively,
573 const String& wildCardPattern = "*") const;
574
580 int findChildFiles (Array<File>& results, int whatToLookFor,
581 bool searchRecursively, const String& wildCardPattern = "*") const;
582
599 int getNumberOfChildFiles (int whatToLookFor,
600 const String& wildCardPattern = "*") const;
601
605 bool containsSubDirectories() const;
606
607 //==============================================================================
625 FileInputStream* createInputStream() const;
626
658 FileOutputStream* createOutputStream (size_t bufferSize = 0x8000) const;
659
660 //==============================================================================
671 bool loadFileAsData (MemoryBlock& result) const;
672
680 String loadFileAsString() const;
681
685 void readLines (StringArray& destLines) const;
686
687 //==============================================================================
694 bool appendData (const void* dataToAppend,
695 size_t numberOfBytes) const;
696
711 bool replaceWithData (const void* dataToWrite,
712 size_t numberOfBytes) const;
713
727 bool appendText (const String& textToAppend,
728 bool asUnicode = false,
729 bool writeUnicodeHeaderBytes = false,
730 const char* lineEndings = "\r\n") const;
731
748 bool replaceWithText (const String& textToWrite,
749 bool asUnicode = false,
750 bool writeUnicodeHeaderBytes = false,
751 const char* lineEndings = "\r\n") const;
752
756 bool hasIdenticalContentTo (const File& other) const;
757
758 //==============================================================================
765 static void findFileSystemRoots (Array<File>& results);
766
770 String getVolumeLabel() const;
771
775 int getVolumeSerialNumber() const;
776
782 int64 getBytesFreeOnVolume() const;
783
789 int64 getVolumeTotalSize() const;
790
792 bool isOnCDRomDrive() const;
793
799 bool isOnHardDisk() const;
800
805 bool isOnRemovableDrive() const;
806
807 //==============================================================================
819 bool startAsProcess (const String& parameters = String()) const;
820
824 void revealToUser() const;
825
826 //==============================================================================
829 enum SpecialLocationType
830 {
832 userHomeDirectory,
833
838 userDocumentsDirectory,
839
841 userDesktopDirectory,
842
844 userMusicDirectory,
845
847 userMoviesDirectory,
848
850 userPicturesDirectory,
851
858 userApplicationDataDirectory,
859
870 commonApplicationDataDirectory,
871
877 commonDocumentsDirectory,
878
882 tempDirectory,
883
895 currentExecutableFile,
896
905 currentApplicationFile,
906
912 invokedExecutableFile,
913
915 hostApplicationPath,
916
917 #if JUCE_WINDOWS || DOXYGEN
919 windowsSystemDirectory,
920 #endif
921
926 globalApplicationsDirectory,
927
928 #if JUCE_WINDOWS || DOXYGEN
936 globalApplicationsDirectoryX86
937 #endif
938 };
939
945 static File JUCE_CALLTYPE getSpecialLocation (const SpecialLocationType type);
946
947 //==============================================================================
952 static File createTempFile (StringRef fileNameEnding);
953
954 //==============================================================================
958 static File getCurrentWorkingDirectory();
959
967 bool setAsCurrentWorkingDirectory() const;
968
969 //==============================================================================
973 static juce_wchar getSeparatorChar();
974
978 static StringRef getSeparatorString();
979
980 //==============================================================================
992 static String createLegalFileName (const String& fileNameToFix);
993
1001 static String createLegalPathName (const String& pathNameToFix);
1002
1004 static bool areFileNamesCaseSensitive();
1005
1007 static bool isAbsolutePath (StringRef path);
1008
1014 static File createFileWithoutCheckingPath (const String& absolutePath) noexcept;
1015
1017 static String addTrailingSeparator (const String& path);
1018
1019 //==============================================================================
1021 bool createSymbolicLink (const File& linkFileToCreate, bool overwriteExisting) const;
1022
1024 bool isSymbolicLink() const;
1025
1029 File getLinkedTarget() const;
1030
1036 static bool createSymbolicLink (const File& linkFileToCreate,
1037 const String& nativePathOfTarget,
1038 bool overwriteExisting);
1039
1042 String getNativeLinkedTarget() const;
1043
1044 #if JUCE_WINDOWS || DOXYGEN
1046 bool createShortcut (const String& description, const File& linkFileToCreate) const;
1047
1049 bool isShortcut() const;
1050 #else
1051
1052 #endif
1053
1054 //==============================================================================
1055 #if JUCE_MAC || JUCE_IOS || DOXYGEN
1057 OSType getMacOSType() const;
1058
1060 bool isBundle() const;
1061 #endif
1062
1063 #if JUCE_MAC || DOXYGEN
1065 void addToDock() const;
1066 #endif
1067
1068 //==============================================================================
1070 struct NaturalFileComparator
1071 {
1072 NaturalFileComparator (bool shouldPutFoldersFirst) noexcept : foldersFirst (shouldPutFoldersFirst) {}
1073
1074 int compareElements (const File& firstFile, const File& secondFile) const
1075 {
1076 if (foldersFirst && (firstFile.isDirectory() != secondFile.isDirectory()))
1077 return firstFile.isDirectory() ? -1 : 1;
1078
1079 #if NAMES_ARE_CASE_SENSITIVE
1080 return firstFile.getFullPathName().compareNatural (secondFile.getFullPathName(), true);
1081 #else
1082 return firstFile.getFullPathName().compareNatural (secondFile.getFullPathName(), false);
1083 #endif
1084 }
1085
1086 bool foldersFirst;
1087 };
1088
1089 /* These static objects are deprecated because it's too easy to accidentally use them indirectly
1090 during a static constructor, which leads to very obscure order-of-initialisation bugs.
1091 Use File::getSeparatorChar() and File::getSeparatorString(), and instead of File::nonexistent,
1092 just use File() or {}.
1093 */
1094 JUCE_DEPRECATED_STATIC (static const juce_wchar separator;)
1095 JUCE_DEPRECATED_STATIC (static const StringRef separatorString;)
1096 JUCE_DEPRECATED_STATIC (static const File nonexistent;)
1097
1098private:
1099 //==============================================================================
1100 String fullPath;
1101
1102 static String parseAbsolutePath (const String&);
1103 String getPathUpToLastSlash() const;
1104
1105 Result createDirectoryInternal (const String&) const;
1106 bool copyInternal (const File&) const;
1107 bool moveInternal (const File&) const;
1108 bool replaceInternal (const File&) const;
1109 bool setFileTimesInternal (int64 m, int64 a, int64 c) const;
1110 void getFileTimesInternal (int64& m, int64& a, int64& c) const;
1111 bool setFileReadOnlyInternal (bool) const;
1112 bool setFileExecutableInternal (bool) const;
1113};
1114
1115} // namespace juce
juce::Array
Definition: juce_Array.h:56
juce::FileInputStream
Definition: juce_FileInputStream.h:35
juce::FileOutputStream
Definition: juce_FileOutputStream.h:35
juce::File
Definition: juce_File.h:41
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:149
juce::File::~File
~File()=default
juce::File::revealToUser
void revealToUser() const
juce::File::SpecialLocationType
SpecialLocationType
Definition: juce_File.h:830
juce::File::userMoviesDirectory
@ userMoviesDirectory
Definition: juce_File.h:847
juce::File::userMusicDirectory
@ userMusicDirectory
Definition: juce_File.h:844
juce::File::tempDirectory
@ tempDirectory
Definition: juce_File.h:882
juce::File::globalApplicationsDirectory
@ globalApplicationsDirectory
Definition: juce_File.h:926
juce::File::userDocumentsDirectory
@ userDocumentsDirectory
Definition: juce_File.h:838
juce::File::currentApplicationFile
@ currentApplicationFile
Definition: juce_File.h:905
juce::File::invokedExecutableFile
@ invokedExecutableFile
Definition: juce_File.h:912
juce::File::commonDocumentsDirectory
@ commonDocumentsDirectory
Definition: juce_File.h:877
juce::File::userApplicationDataDirectory
@ userApplicationDataDirectory
Definition: juce_File.h:858
juce::File::userPicturesDirectory
@ userPicturesDirectory
Definition: juce_File.h:850
juce::File::commonApplicationDataDirectory
@ commonApplicationDataDirectory
Definition: juce_File.h:870
juce::File::userDesktopDirectory
@ userDesktopDirectory
Definition: juce_File.h:841
juce::File::hostApplicationPath
@ hostApplicationPath
Definition: juce_File.h:915
juce::File::currentExecutableFile
@ currentExecutableFile
Definition: juce_File.h:895
juce::File::userHomeDirectory
@ userHomeDirectory
Definition: juce_File.h:832
juce::File::TypesOfFileToFind
TypesOfFileToFind
Definition: juce_File.h:548
juce::File::getSeparatorChar
static juce_wchar getSeparatorChar()
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:39
juce::String::compareNatural
int compareNatural(StringRef other, bool isCaseSensitive=false) const noexcept
Definition: juce_String.cpp:712
juce::Time
Definition: juce_Time.h:37
juce::File::NaturalFileComparator
Definition: juce_File.h:1071