00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <fstream.h>
00029 #include <UT/UT_DSOVersion.h>
00030 #include <UT/UT_EnvControl.h>
00031 #include <UT/UT_NTStreamUtil.h>
00032 #include <UT/UT_DirUtil.h>
00033 #include <UT/UT_SysClone.h>
00034 #include "FS_HomeHelper.h"
00035
00036 #define HOME_SIGNATURE "home:"
00037 #define HOME_SIGNATURE_LEN 5
00038
00039 void
00040 installFSHelpers()
00041 {
00042 new HDK_Sample::FS_HomeReadHelper();
00043 new HDK_Sample::FS_HomeWriteHelper();
00044 new HDK_Sample::FS_HomeInfoHelper();
00045 }
00046
00047 using namespace HDK_Sample;
00048
00049 static bool
00050 prefixPathWithHome(UT_String &destpath, const char *srcpath)
00051 {
00052 if( strncmp(srcpath, HOME_SIGNATURE, HOME_SIGNATURE_LEN) == 0 )
00053 {
00054 destpath = UT_EnvControl::getString(ENV_HOME);
00055
00056 if( srcpath[HOME_SIGNATURE_LEN] != '/' )
00057 destpath += "/";
00058 destpath += &srcpath[HOME_SIGNATURE_LEN];
00059
00060 return true;
00061 }
00062
00063 return false;
00064 }
00065
00066 FS_HomeReadHelper::FS_HomeReadHelper()
00067 {
00068 UTaddAbsolutePathPrefix(HOME_SIGNATURE);
00069 }
00070
00071 FS_HomeReadHelper::~FS_HomeReadHelper()
00072 {
00073 }
00074
00075 FS_ReaderStream *
00076 FS_HomeReadHelper::createStream(const char *source)
00077 {
00078 FS_ReaderStream *is = 0;
00079 UT_String homepath;
00080
00081 if( prefixPathWithHome(homepath, source) )
00082 is = new FS_ReaderStream(homepath);
00083
00084 return is;
00085 }
00086
00087 FS_HomeWriteHelper::FS_HomeWriteHelper()
00088 {
00089 UTaddAbsolutePathPrefix(HOME_SIGNATURE);
00090 }
00091
00092 FS_HomeWriteHelper::~FS_HomeWriteHelper()
00093 {
00094 }
00095
00096 FS_WriterStream *
00097 FS_HomeWriteHelper::createStream(const char *source)
00098 {
00099 FS_WriterStream *os = 0;
00100 UT_String homepath;
00101
00102 if( prefixPathWithHome(homepath, source) )
00103 os = new FS_WriterStream(homepath);
00104
00105 return os;
00106 }
00107
00108 FS_HomeInfoHelper::FS_HomeInfoHelper()
00109 {
00110 UTaddAbsolutePathPrefix(HOME_SIGNATURE);
00111 }
00112
00113 FS_HomeInfoHelper::~FS_HomeInfoHelper()
00114 {
00115 }
00116
00117 bool
00118 FS_HomeInfoHelper::canHandle(const char *source)
00119 {
00120 return (strncmp(source, HOME_SIGNATURE, HOME_SIGNATURE_LEN) == 0);
00121 }
00122
00123 bool
00124 FS_HomeInfoHelper::hasAccess(const char *source, int mode)
00125 {
00126 UT_String homepath;
00127
00128 if( prefixPathWithHome(homepath, source) )
00129 {
00130 FS_Info info(homepath);
00131
00132 return info.hasAccess(mode);
00133 }
00134
00135 return false;
00136 }
00137
00138 bool
00139 FS_HomeInfoHelper::getIsDirectory(const char *source)
00140 {
00141 UT_String homepath;
00142
00143 if( prefixPathWithHome(homepath, source) )
00144 {
00145 FS_Info info(homepath);
00146
00147 return info.getIsDirectory();
00148 }
00149
00150 return false;
00151 }
00152
00153 int
00154 FS_HomeInfoHelper::getModTime(const char *source)
00155 {
00156 UT_String homepath;
00157
00158 if( prefixPathWithHome(homepath, source) )
00159 {
00160 FS_Info info(homepath);
00161
00162 return info.getModTime();
00163 }
00164
00165 return 0;
00166 }
00167
00168 int64
00169 FS_HomeInfoHelper::getSize(const char *source)
00170 {
00171 UT_String homepath;
00172
00173 if( prefixPathWithHome(homepath, source) )
00174 {
00175 FS_Info info(homepath);
00176
00177 return info.getFileDataSize();
00178 }
00179
00180 return 0;
00181 }
00182
00183 bool
00184 FS_HomeInfoHelper::getContents(const char *source,
00185 UT_StringArray &contents,
00186 UT_StringArray *dirs)
00187 {
00188 UT_String homepath;
00189
00190 if( prefixPathWithHome(homepath, source) )
00191 {
00192 FS_Info info(homepath);
00193
00194 return info.getContents(contents, dirs);
00195 }
00196
00197 return false;
00198 }
00199