| 110 | } |
| 111 | |
| 112 | void PropertyFileIncluded::setValue(const char* sFile, const char* sName) |
| 113 | { |
| 114 | if (!Base::Tools::isNullOrEmpty(sFile)) { |
| 115 | if (_cValue == sFile) { |
| 116 | throw Base::FileSystemError("Not possible to set the same file!"); |
| 117 | } |
| 118 | |
| 119 | // keep the path to the original file |
| 120 | _OriginalName = sFile; |
| 121 | |
| 122 | std::string pathTrans = getDocTransientPath(); |
| 123 | Base::FileInfo file(sFile); |
| 124 | std::string path = file.dirPath(); |
| 125 | if (!file.exists()) { |
| 126 | std::stringstream str; |
| 127 | str << "File " << file.filePath() << " does not exist."; |
| 128 | throw Base::FileSystemError(str.str()); |
| 129 | } |
| 130 | |
| 131 | aboutToSetValue(); // undo/redo by moving the file away with temp name |
| 132 | |
| 133 | // remove old file (if not moved by undo) |
| 134 | Base::FileInfo value(_cValue); |
| 135 | std::string pathAct = value.dirPath(); |
| 136 | if (value.exists()) { |
| 137 | value.setPermissions(Base::FileInfo::ReadWrite); |
| 138 | value.deleteFile(); |
| 139 | } |
| 140 | |
| 141 | // if a special name given, use this instead |
| 142 | if (sName) { |
| 143 | Base::FileInfo fi(pathTrans + "/" + sName); |
| 144 | if (fi.exists()) { |
| 145 | // if a file with this name already exists search for a new one |
| 146 | std::string dir = pathTrans; |
| 147 | std::string fnp = fi.fileNamePure(); |
| 148 | std::string ext = fi.extension(); |
| 149 | int i = 0; |
| 150 | do { |
| 151 | i++; |
| 152 | std::stringstream str; |
| 153 | str << dir << "/" << fnp << i; |
| 154 | if (!ext.empty()) { |
| 155 | str << "." << ext; |
| 156 | } |
| 157 | fi.setFile(str.str()); |
| 158 | } while (fi.exists()); |
| 159 | |
| 160 | _cValue = fi.filePath(); |
| 161 | _BaseFileName = fi.fileName(); |
| 162 | } |
| 163 | else { |
| 164 | _cValue = pathTrans + "/" + sName; |
| 165 | _BaseFileName = sName; |
| 166 | } |
| 167 | } |
| 168 | else if (value.fileName().empty()) { |
| 169 | _cValue = pathTrans + "/" + file.fileName(); |
nothing calls this directly
no test coverage detected