InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FileUtils Class Reference

Public Types

enum  ViewMode { kNormal, kOpenNewWindow, kOpenMaximized }
 
enum  Access { kRead, kWrite, kReadWrite }
 

Static Public Member Functions

static char GetDirectorySeperator ()
 
static bool16 SetAppFolder (SysConnection appResourceHandle=nil)
 
static bool16 GetAppFolder (IDFile *appFolder)
 
static bool16 GetAppFolder (PMString *appFolder)
 
static bool16 GetAppPath (IDFile *appPath)
 
static bool16 GetAppSubFolder (IDFile *result, const PMString &subFolderName)
 
static bool16 GetUserRoamingFolder (IDFile *result, const PMString &appFolder, const PMString &subFolderName)
 
static bool16 GetAppLocalCachedDataFolder (IDFile *result, const PMString &subFolderName)
 
static bool16 GetAppRoamingDataFolder (IDFile *result, const PMString &subFolderName)
 
static bool16 GetAppDocumentFolder (IDFile *result, const PMString &subFolderName)
 
static bool16 GetRecoveryFolder (IDFile *result, const PMString &subFolderName)
 
static bool16 GetUserDictionariesFolder (IDFile *result, const PMString &subFolderName)
 
static bool16 SetCurrentFolder (const IDFile &targetFolder)
 
static bool16 GetCurrentFolder (IDFile *currentFolder)
 
static void AppendPath (IDFile *originalPath, const PMString &pathToAppend)
 
static void GetFileName (const IDFile &fSpec, PMString &fileName)
 
static void GetFileName (const PMString &pathStr, PMString &fileName)
 
static bool16 IsEqual (const IDFile &file1, const IDFile &file2)
 
static bool SwapFiles (const IDFile &file1, const IDFile &file2)
 
static void IDFileToPMString (const IDFile &file, PMString &pathStr)
 
static void PMStringToIDFile (const PMString &pathStr, IDFile &file)
 
static PMString SysFileToPMString (const IDFile &file)
 
static IDFile PMStringToSysFile (const PMString &pathStr)
 
static PMString SysFileToFileURL (const IDFile &fSpec)
 
static PMString PMStringToFileURL (const PMString &fileName)
 
static PMString PMStringToURL (const PMString &str)
 
static PMString URLToPMString (const std::string &URL)
 
static std::string UTF8ToURL (const std::string &str, const char kSeparator)
 
static std::string URLToUTF8 (const std::string &fileURL, bool &ContainsUTF16)
 
static PMString FileURLToPMString (const std::string &fileURL)
 
static PMString FileURLToPMString (const PMString &__fileURL)
 
static IDFile FileURLToSysFile (const std::string &__fileURL, bool *isReturingAValidSysFile=NULL)
 
static IDFile FileURLToSysFile (const PMString &__fileURL, bool *isReturingAValidSysFile=NULL)
 
static PMStringCreateResolvedPathName (const PMString &pathName)
 
static uint32 SpaceAvail (const IDFile &diskToCheck)
 
static bool16 IsDirectory (const IDFile &fileSpec)
 
static bool16 CreateFolderIfNeeded (const IDFile &folderFileSpec, bool16 bCreateParent=kFalse)
 
static bool16 CopyFile (const IDFile &srcFile, const IDFile &dstFile)
 
static bool16 MoveFile (const IDFile &srcFile, const IDFile &dstFolder, IDFile *dstFile=NULL)
 
static bool16 GetParentDirectory (IDFile const &file, IDFile &parent)
 
static bool16 DoesFileExist (const IDFile &fileSpec)
 
static void GetPathOnly (const IDFile &fileSpec, PMString &pathName, bool16 includeSeparator=kFalse)
 
static void GetBaseFileName (const IDFile &inFile, PMString &outString)
 
static void GetBaseFileName (const PMString &inString, PMString &outString)
 
static void GetExtension (const IDFile &inFile, PMString &outString)
 
static uint32 GetFileSize (const IDFile &fileSpec, bool16 includeResourceFork=kFalse)
 
static bool16 GetOpenFileType (const IDFile &sysFile, SysFileType &type)
 
static bool16 GetStreamFileType (IPMStream *stream, SysFileType &type)
 
static void GetVolumeName (const IDFile *fileOrFolderSpec, PMString *volumeName)
 
static bool16 OnSameVolume (const IDFile &file1, const IDFile &file2)
 
static int32 ShowFile (const IDFile &fileSpec)
 
static ErrorCode BrowseToFile (const IDFile *fileSpec, ViewMode mode=kNormal)
 
static ErrorCode OpenFileInEditor (const IDFile &fileToOpen, const AppInfo &appInfo=kNullAppInfo, PMString *errorString=nil)
 
static bool16 IsNetworkDrive (const IDFile &sysFile)
 
static bool16 GetAppInstallationFolder (IDFile *folder)
 
static bool16 GetPresetsFolder (IDFile *folder, const PMString &subFolderName, const PMLocaleId &localeId)
 
static void AppendLocalizedFolder (IDFile *folder, const PMLocaleId &localeId)
 
static bool16 GetModificationDate (const IDFile &spec, uint32 *modDate)
 
static bool8 CanOpen (const IDFile &spec, Access access=kReadWrite)
 
static void PrefixFileURL (const PMString &prefix, PMString &fileURL)
 
static FILE * OpenFile (const IDFile &file, const char *mode)
 
static FILE * OpenFile (const PMString &path, const char *mode)
 
static FILE * OpenFile (const char *path, const char *mode)
 
static bool16 IsAppRoamingDataFolderNew ()
 
static bool16 GetAppLocalCachedDataFolderSansLocale (IDFile *result)
 
static textchar GetDirectorySeparatorTextChar ()
 
static bool16 IsTemplate (const IDFile &file)
 
static bool16 IsTempFile (const IDFile &file)
 
static void CreateUniqueFileName (PMString &fileName)
 
static IDataBase::DBResultCode CheckFileAccessibleForSaving (const IDFile &destFile)
 
static PMString GetDirectorySeparatorPMString ()
 
static void AppendPaths (IDFile *originalPath, const std::vector< PMString > &pathsToAppend)
 
static void AppendPaths (IDFile *originalPath, const std::vector< const wchar_t * > &pathsToAppend)
 
static char GetPosixDirectorySeparator ()
 
static textchar GetPosixDirectorySeparatorTextChar ()
 
static PMString GetPosixDirectorySeparatorPMString ()
 
static CFURLPathStyle GetMacPathStyle ()
 
static char GetMacDirectorySeparator ()
 
static textchar GetMacDirectorySeparatorTextChar ()
 
static PMString GetMacDirectorySeparatorPMString ()
 

Member Function Documentation

static void FileUtils::AppendLocalizedFolder (IDFilefolder,
const PMLocaleIdlocaleId 
)
static

Appends a localized folder name to the passed in folder argument. The folder name that is appended corresponds to the current user interface id in current locale. e.g. if presets folder was passed in, would append "en_US" for English, "fr_FR" for French, etc.

Parameters
folderIN/OUT the output path to modify
localeIdIN Will append a localized folder name (e.g. "en_US") depending on PMLocaleId passed in. Typically LocaleSetting::GetLocale() is passed for this argument. However, you can pass an default PMLocaleId() if you want no localized folder appended.
static void FileUtils::AppendPaths (IDFileoriginalPath,
const std::vector< PMString > & pathsToAppend 
)
static

Appends a vector of paths to IDFile object

Parameters
originalPathIN IDFile object to append paths
pathsToAppendIN PMString paths to be appended to IDFile in the given order
static void FileUtils::AppendPaths (IDFileoriginalPath,
const std::vector< const wchar_t * > & pathsToAppend 
)
static

Appends a vector of paths to IDFile object

Parameters
originalPathIN IDFile object to append paths
pathsToAppendIN wchar_t* paths to be appended to IDFile in the given order
static IDataBase::DBResultCode FileUtils::CheckFileAccessibleForSaving (const IDFiledestFile)
static

Check if file is accessible for saving.

Parameters
destFileIN IDFile destination file path
Returns
kNoError if the destFile is accesible, kAccessDenied if it is not.
static void FileUtils::CreateUniqueFileName (PMStringfileName)
static

Creates a unique file name incorporating the base file name passed in as parameter and appending process and/or thread id and some timestamp info. File name generated is not guaranteed to not already exist. This is typically used only for generating unique names for temporary files. If the calling code needs to ensure that an existing file is not overwritten, it should check for file existence and retry this function call (only the timestamp info will change in subsequent retries).

Parameters
fileNameIN/OUT incoming base file name, generated name is returned via this parameter.
static PMString FileUtils::FileURLToPMString (const std::string & fileURL)
static

FileURLToPMString the perfered function call is static PMString FileURLToPMString (const std::string &__fileURL);

FileURLToPMString converts from a file url to a PMString system path on the pc this system path will eather be a UNC path if the url species a file not on the local host (file:/// or file://localhost/) and otherwise the encoded system path UNC path = \myhost System path = c:

On the mac the path returned will be a path made up of 31 char FsSpec file names if the Posix path is desired FileURLToPosixPath can be called. mac path: "my hd:my folder:my file"

Parameters
fileURLFile URL
Returns
system path encoded as a pmstring
See Also
PMStringToFileURL, FileURLToPosixPath (mac only)
static PMString FileUtils::FileURLToPMString (const PMString__fileURL)
static

FileURLToPMString the perfered function call is static PMString FileURLToPMString (const std::string &__fileURL);

FileURLToPMString converts from a file url to a PMString system path on the pc this system path will eather be a UNC path if the url species a file not on the local host (file:/// or file://localhost/) and otherwise the encoded system path UNC path = \myhost System path = c:

On the mac the path returned will be a path made up of 31 char FsSpec file names if the Posix path is desired FileURLToPosixPath can be called. mac path: "my hd:my folder:my file"

Parameters
fileURLFile URL
Returns
system path encoded as a pmstring
See Also
PMStringToFileURL, FileURLToPosixPath (mac only)
static IDFile FileUtils::FileURLToSysFile (const std::string & __fileURL,
bool * isReturingAValidSysFile = NULL 
)
static

FileURLToSysFile converts from a file url to a sysfile static IDFile FileURLToSysFile(const std::string& __fileURL, bool *isReturingAValidSysFile = NULL); is the prefered function call

PC: on the PC this function should always succeeds aka (isReturingAValidSysFile should always be set to true on exit) if the url descibes a UNC path the file returned will obviously be a unc file path if the URL isn't unc the sysfile returned will be a standard path/

file://myhost/mydir/myfile will result in \myhost file://localhost/c:/mydir/myfile will result in c: file:///c:/mydir/myfile will result in c:

MAC: On the Mac FSSpec can be made to point to files that don't exist, but the directory heiarchary must exist so this function might fail. if it fails the optional paramater isReturingAValidSysFile will return false and the FSSpec returned in the sysfile should be zeroed and it shouldn't have a truename The mac also cant take UNC paths so don't even think about them.

If the URL decribes a directory which exists but a file which doesn't the function will succeed but the FSSpec will point to a file which doesn't exist. The TrueName for the FSSpec is set to the Unicode name described in the FileURL, the FSSpec name is set to a 31 byte platform char name. If the URL name is greater then 31 characters then it is truncated.

file:///myfolder/myfile Valid FSSpec if my folder exists on the default vol file://localhost/myfolder/myfile Valid FSSpec if my folder exists on the default vol

Parameters
__fileURLFile URL to convert to a sys file
isReturingAValidSysFileoptional paramater, if a bool is passed in, the bool will be set to true if a valid IDFile is being returned on the PC this is always true, on the mac it can be true or false (see above)
Returns
IDFile to the File URL, on the PC the sys file might not exist but is a valid description, on the mac the sys file might not be valid
See Also
SysFileToFileURL, FileURLToPosixPath (mac only)
static IDFile FileUtils::FileURLToSysFile (const PMString__fileURL,
bool * isReturingAValidSysFile = NULL 
)
static

FileURLToSysFile converts from a file url to a sysfile static IDFile FileURLToSysFile(const std::string& __fileURL, bool *isReturingAValidSysFile = NULL); is the prefered function call

PC: on the PC this function should always succeeds aka (isReturingAValidSysFile should always be set to true on exit) if the url descibes a UNC path the file returned will obviously be a unc file path if the URL isn't unc the sysfile returned will be a standard path/

file://myhost/mydir/myfile will result in \myhost file://localhost/c:/mydir/myfile will result in c: file:///c:/mydir/myfile will result in c:

MAC: On the Mac FSSpec can be made to point to files that don't exist, but the directory heiarchary must exist so this function might fail. if it fails the optional paramater isReturingAValidSysFile will return false and the FSSpec returned in the sysfile should be zeroed and it shouldn't have a truename The mac also cant take UNC paths so don't even think about them.

If the URL decribes a directory which exists but a file which doesn't the function will succeed but the FSSpec will point to a file which doesn't exist. The TrueName for the FSSpec is set to the Unicode name described in the FileURL, the FSSpec name is set to a 31 byte platform char name. If the URL name is greater then 31 characters then it is truncated.

file:///myfolder/myfile Valid FSSpec if my folder exists on the default vol file://localhost/myfolder/myfile Valid FSSpec if my folder exists on the default vol

Parameters
__fileURLFile URL to convert to a sys file
isReturingAValidSysFileoptional paramater, if a bool is passed in, the bool will be set to true if a valid IDFile is being returned on the PC this is always true, on the mac it can be true or false (see above)
Returns
IDFile to the File URL, on the PC the sys file might not exist but is a valid description, on the mac the sys file might not be valid
See Also
SysFileToFileURL, FileURLToPosixPath (mac only)
static bool16 FileUtils::GetAppLocalCachedDataFolder (IDFileresult,
const PMStringsubFolderName 
)
static

Finds a specified sub-folder of the local cached application data folder. Creates the sub-folder if it doesn't already exist. This is designed for large data caches that you would not want to roam from machine to machine in a roaming profiles environment on Windows, and for data that can be easily regenerated if deleted. On Windows XP, for example, this might return: "%USERHOME%\Local Settings\Application Data\Adobe\InDesign\Version x.y\en_US\Caches\subFolderName" On Macintosh, for example, this might return: "~/Library/Caches/Adobe InDesign/Version x.y/en_US/subFolderName"

Parameters
resultOUT IDFile of the sub folder within the local cached data folder.
subFolderNameIN Subfolder within the local cached data folder to return.
See Also
GetAppRoamingDataFolder
AppendLocalizedFolder
static bool16 FileUtils::GetAppLocalCachedDataFolderSansLocale (IDFileresult)
static

Get the local cached application data folder without the locale sub-folder. This function does not create the data folder.

Parameters
resultOUT IDFile of the folder.
See Also
GetAppLocalCachedDataFolder
GetAppRoamingDataFolder
AppendLocalizedFolder
static bool16 FileUtils::GetAppRoamingDataFolder (IDFileresult,
const PMStringsubFolderName 
)
static

Finds a specified sub-folder of the roaming application data folder. Creates the sub-folder if it doesn't already exist. This is designed for "normal" preference data that you would want to roam from machine to machine in a roaming profiles environment on Windows. On Windows XP, for example, this might return: "%USERHOME%\Application Data\Adobe\InDesign\Version x.y\en_US\subFolderName" On Macintosh, for example, this might return: "~/Library/Preferences/Adobe InDesign/Version x.y/en_US/subFolderName"

Parameters
resultOUT IDFile of the sub folder within the roaming data folder.
subFolderNameIN Subfolder within the roaming data folder to return.
See Also
GetAppLocalCachedDataFolder
GetPresetsFolder
AppendLocalizedFolder
static PMString FileUtils::GetDirectorySeparatorPMString ()
static

Returns the directory separator in type PMString

Returns
directory separator
static char FileUtils::GetMacDirectorySeparator ()
static

Returns the Mac directory separator in type char

Returns
Mac directory separator
static PMString FileUtils::GetMacDirectorySeparatorPMString ()
static

Returns the Mac directory separator in type PMString

Returns
Mac directory separator
static textchar FileUtils::GetMacDirectorySeparatorTextChar ()
static

Returns the Mac directory separator in type textChar

Returns
Mac directory separator
static CFURLPathStyle FileUtils::GetMacPathStyle ()
static

Returns the Mac Path-Style

Returns
Mac Path-style in type CFURLPathStyle
static char FileUtils::GetPosixDirectorySeparator ()
static

Internal use only Returns the Posix-Style directory separator in type char

Returns
Posix Path-Style directory separator
static PMString FileUtils::GetPosixDirectorySeparatorPMString ()
static

Internal use only Returns the Posix-Style directory separator in type PMString

Returns
Posix Path-Style directory separator
static textchar FileUtils::GetPosixDirectorySeparatorTextChar ()
static

Internal use only Returns the Posix-Style directory separator in type textChar

Returns
Posix Path-Style directory separator
static bool16 FileUtils::GetPresetsFolder (IDFilefolder,
const PMStringsubFolderName,
const PMLocaleIdlocaleId 
)
static

Return the presets folder with a subfolder appended, and optionally a localized folder appended as well. If you need just the Presets directory, you can pass an empty subFolderName and PMLocaleId().

Parameters
folderIN/OUT the output path to a location within the Presets folder
subFolderNameIN An optional subfolder with the Presets folder to append to the output path. May pass an empty string if not needed.
localeIdIN Will append a localized folder name (e.g. "en_US") depending on PMLocaleId passed in. Typically LocaleSetting::GetLocale() is passed for this argument. However, you can pass an default PMLocaleId() if you want no localized folder appended.
static void FileUtils::IDFileToPMString (const IDFilefile,
PMStringpathStr 
)
static

Converts an IDFile to a system path string.

Parameters
fileIN IDFile to convert to a string.
pathStrOUT Resulting path string.\ On Windows, the path is a UNC or local path: "C:\My Programs\adobe\indesign.exe".\ On the mac, the path is an POSIX path: "/Applications/Adobe InDesign CS2".
See Also
PMStringToIDFile
static bool16 FileUtils::IsTempFile (const IDFilefile)
static

Checks if the file is a temporary file.

Returns
kTrue if the file is created in temp directory, kFalse if it is not.
static bool16 FileUtils::IsTemplate (const IDFilefile)
static

Checks if the file is an InDesign Template file.

Returns
kTrue if the file is InDesign Template, kFalse if it is not.
static FILE* FileUtils::OpenFile (const IDFilefile,
const char * mode 
)
static

Opens the file.

Parameters
fileIN File to open.
modeIN Flags denoting type of access permitted (see fopen).
Returns
A pointer to the open file if successful, else NULL.
static FILE* FileUtils::OpenFile (const PMStringpath,
const char * mode 
)
static

Opens the file referenced by the path.

Parameters
fileIN Path of file to open. An POSIX path on Mac.
modeIN Flags denoting type of access permitted (see fopen).
Returns
A pointer to the open file if successful, else NULL.
static FILE* FileUtils::OpenFile (const char * path,
const char * mode 
)
static

Opens the file referenced by the path.

Parameters
fileIN Path of file to open. An POSIX path on Mac.
modeIN Flags denoting type of access permitted (see fopen).
Returns
A pointer to the open file if successful, else NULL.
static PMString FileUtils::PMStringToFileURL (const PMStringfileName)
static

Convert from a fully qualified path name to a standard file URL (file://).

Parameters
fileNameOn the PC the filename string will be a system path like "C:\my programs\adobe\indesign.exe" or a UNC path like "\\myServer\mydir\myfile.txt" on the mac the string will be a path made up of FSspec path names (31 byte limit), this path might not look quite correct but it should be in platform encodeing mac path: "/Applications/Adobe/InDesign CS" DON"T PASS RAW UTF16 in here!
Returns
a valid file URL.
See Also
FileURLToPMString note: Post Dragontail this should be fixed to return a std::string
static void FileUtils::PMStringToIDFile (const PMStringpathStr,
IDFilefile 
)
static

Converts from a system path string to an IDFile.

Parameters
pathStrIN String containing the path to convert to an IDFile.\ On Windows, the path is a UNC or local path: "C:\My Programs\adobe\indesign.exe".\ On the Mac, the path is an POSIX path: "/Applications/Adobe InDesign CS2".
fileOUT Resulting IDFile object.
See Also
IDFileToPMString
static IDFile FileUtils::PMStringToSysFile (const PMStringpathStr)
static

Converts from a system path string to an IDFile.

Parameters
pathStrIN String containing the path to convert to an IDFile.\ On Windows, the path is a UNC or local path: "C:\My Programs\adobe\indesign.exe".\ On the Mac, the path is an POSIX path: "/Applications/Adobe InDesign CS2".
Returns
Resulting IDFile object.
See Also
SysFileToPMString
static PMString FileUtils::PMStringToURL (const PMStringstr)
static

Converts a string into URL encodeing, basicly does a PMString->UTF8Encodeing->URLEncodeing

Parameters
strthe string to convert into URL encodeing
Returns
the string in url encodeing
See Also
URLToPMString note: Post Dragontail this should be fixed to return a std::string
static void FileUtils::PrefixFileURL (const PMStringprefix,
PMStringfileURL 
)
static

PrefixFileURL appends a prefix string after the file:/// or file:// in a file url. This function serves really no purpose other then being a helper function to some junky code thrown around PLEASE don't use this.. It should really go away in the next version...

If a file url isn't passed in then this code will assert, and the url will be returned.

Example: PrefixFileURL ("123","file://myfile.jpg") == file://123myfile.jpg PrefixFileURL ("123","file:///myfile.jpg") == file:///123myfile.jpg PrefixFileURL ("123","file:////myfile.jpg") == file:///123/myfile.jpg PrefixFileURL ("123","file:/myfile.jpg") == ASSERT + file:/myfile.jpg PrefixFileURL ("123","http://myfile.jpg") == ASSERT + http://myfile.jpg

Parameters
prefixprefix to append
fileURLfile url to add the prefix to.
static PMString FileUtils::SysFileToFileURL (const IDFilefSpec)
static

Convert from a IDFile to a standard file URL.

Parameters
fSpeca IDFile (System specifc file system path on the mac this is a wrapper around the FSSpec on the PC its a standard path). The PC can point to eather a local file("c:\mydir\myfile") or a file on a remote host ("\\myhost\mydir\myfile"). On the Mac all remote files are accessed via mounted volumes so all SysFiles are local
Returns
Returns a file url to the sys file.
See Also
FileURLToSysFile note post dragontail this should be fixed to return a std::string
static PMString FileUtils::SysFileToPMString (const IDFilefile)
static

Converts an IDFile to a system path string.

Parameters
fileIN IDFile to convert to a string.
Returns
Resulting path string. On Windows, the path is a UNC or local path: "C:\My Programs\adobe\indesign.exe".\ On the mac, the path is an POSIX path: "/Applications/Adobe InDesign CS2".
See Also
PMStringToSysFile
static PMString FileUtils::URLToPMString (const std::string & URL)
static

URLToPMString takes a URL and decodes it and returns the string this function is basilcy URLToUTF8Encodeing and then a UTF8EncodeingToWideString. The second transformation is only done if needed Note any part of a URL can be passed in.

Parameters
URLstring to convert from URL encodeing to a string
Returns
The string encodeing
See Also
PMStringToURL
static std::string FileUtils::URLToUTF8 (const std::string & fileURL,
bool & ContainsUTF16 
)
static

URLToUTF8 converts from a URL to UTF8 encoded string

Parameters
fileURLis the URL to convert
ContainsUTF16is a flag set if the returned UTF8 string encodes UTF16 chars
Returns
UTF8 version of the URL
See Also
UTF8ToURL, FileURLToPosixPath (mac only)
static std::string FileUtils::UTF8ToURL (const std::string & str,
const char kSeparator 
)
static

UTF8ToURL converts from a UTF8 encoded string to a URLencoded string

Parameters
stris the UTF8 encoded string
kSeparatoris file seperator in the UTF8 str, the file seperator will be converted to a url seperator '/' if no conversion is desired then '/' should be passed in. If a PC path was being sent in, in a UTF8 encodeing then the seperator would be '\', if a mac posix path was being sent in the seperator would be '/'
Returns
The URL encodeing of the UTF8 string
See Also
URLToUTF8