| 1 | // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/miscellaneous/iofactory.cpp`/ |
| 2 | |
| 3 | #include "miscellaneous/iofactory.h"cxx . . $ `<file>/src/librssguard/miscellaneous/iofactory.h`/ |
| 4 | |
| 5 | #include "definitions/definitions.h"cxx . . $ `<file>/src/librssguard/definitions/definitions.h`/ |
| 6 | #include "exceptions/ioexception.h"cxx . . $ `<file>/src/librssguard/exceptions/ioexception.h`/ |
| 7 | #include "exceptions/processexception.h"cxx . . $ `<file>/src/librssguard/exceptions/processexception.h`/ |
| 8 | |
| 9 | #include <QDataStream> |
| 10 | #include <QDir> |
| 11 | #include <QFile> |
| 12 | #include <QFileInfo> |
| 13 | #include <QObject> |
| 14 | #include <QProcess> |
| 15 | #include <QTemporaryFile> |
| 16 | |
| 17 | IOFactorycxx . . $ IOFactory#::IOFactorycxx . . $ IOFactory#IOFactory(49f6e7a06ebc5aa8).() = default; |
| 18 | |
| 19 | bool IOFactorycxx . . $ IOFactory#::isFolderWritablecxx . . $ IOFactory#isFolderWritable(e1defb592416720d).(const QStringcxx . . $ QString#& folder) { |
| 20 | QStringcxx . . $ QString# real_file = foldercxx . . $ QString#QString(132dd6869045752b).; |
| 21 | |
| 22 | if (!real_file.endsWithcxx . . $ QString#endsWith(7cf081d1b6a1defd).(QDircxx . . $ QDir#::separatorcxx . . $ QDir#separator(44eb9225326fcbf5).())) { |
| 23 | real_file +=cxx . . $ QString#`operator+=`(3a2ffbdf8ecc25e2). QDircxx . . $ QDir#::separatorcxx . . $ QDir#separator(44eb9225326fcbf5).(); |
| 24 | } |
| 25 | |
| 26 | real_file +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("test-permissions-file"); |
| 27 | return QTemporaryFilecxx . . $ QTemporaryFile#QTemporaryFile(3520e46b33348bf6).(real_file).opencxx . . $ QTemporaryFile#open(c9857a73d68e59ba).(); |
| 28 | } |
| 29 | |
| 30 | QStringcxx . . $ QString# IOFactorycxx . . $ IOFactory#::getSystemFoldercxx . . $ IOFactory#getSystemFolder(7d8b34fbb6a9c1bf).(QStandardPathscxx . . $ QStandardPaths#::StandardLocationcxx . . $ QStandardPaths#StandardLocation# location) { |
| 31 | QStringListcxx . . $ QStringList# locations = QStandardPathscxx . . $ QStandardPaths#::standardLocationscxx . . $ QStandardPaths#standardLocations(e4a33913b0362450).(location); |
| 32 | |
| 33 | return locations.isEmptycxx . . $ QList#isEmpty(3482b152b9333168).() ? QStringcxx . . $ QString#QString(ced63f7c635d850d).() : locationscxx . . $ QString#QString(132dd6869045752b)..atcxx . . $ QList#at(c7965f769b39929).(0); |
| 34 | } |
| 35 | |
| 36 | QStringcxx . . $ QString# IOFactorycxx . . $ IOFactory#::ensureUniqueFilenamecxx . . $ IOFactory#ensureUniqueFilename(e9cecc7c907e7d19).(const QStringcxx . . $ QString#& name, const QStringcxx . . $ QString#& append_format) { |
| 37 | if (!QFilecxx . . $ QFile#::existscxx . . $ QFile#exists(e1defb592416720d).(name)) { |
| 38 | return namecxx . . $ QString#QString(132dd6869045752b).; |
| 39 | } |
| 40 | |
| 41 | QStringcxx . . $ QString# tmp_filename = namecxx . . $ QString#QString(132dd6869045752b).; |
| 42 | int i = 1; |
| 43 | |
| 44 | while (QFilecxx . . $ QFile#::existscxx . . $ QFile#exists(e1defb592416720d).(tmp_filename)) { |
| 45 | tmp_filename =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). name; |
| 46 | const int index = tmp_filename.lastIndexOfcxx . . $ QString#lastIndexOf(aa6b5e61941c3c07).(QL1Ccxx . . $ `src/librssguard/definitions/definitions.h:455:9`!('.')); |
| 47 | const QStringcxx . . $ QString# append_string = append_format.argcxx . . $ QString#arg(ed67e9a87de2cd4e).(i++); |
| 48 | |
| 49 | if (index < 0) { |
| 50 | tmp_filename.appendcxx . . $ QString#append(6a89d0b7f4d2681c).(append_string); |
| 51 | } |
| 52 | else { |
| 53 | tmp_filename =cxx . . $ QString#`operator=`(4f35bf974e7f8568). tmp_filename.leftcxx . . $ QString#left(32d917b74df1c30e).(index) +cxx . . $ operator+(adfbdceb504720ce). append_string +cxx . . $ operator+(adfbdceb504720ce). tmp_filename.midcxx . . $ QString#mid(5eea715ff28b9227).(index); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return tmp_filenamecxx . . $ QString#QString(28715ad661ad3cec).; |
| 58 | } |
| 59 | |
| 60 | QStringcxx . . $ QString# IOFactorycxx . . $ IOFactory#::filterBadCharsFromFilenamecxx . . $ IOFactory#filterBadCharsFromFilename(fd988a2ab94d906b).(const QStringcxx . . $ QString#& name) { |
| 61 | QStringcxx . . $ QString# value = namecxx . . $ QString#QString(132dd6869045752b).; |
| 62 | |
| 63 | value.replacecxx . . $ QString#replace(8514d9896be75a4a).(QL1Ccxx . . $ `src/librssguard/definitions/definitions.h:455:9`!('/'), QL1Ccxx . . $ `src/librssguard/definitions/definitions.h:455:9`!('-')); |
| 64 | value.removecxx . . $ QString#remove(30270fe3985671e6).(QL1Ccxx . . $ `src/librssguard/definitions/definitions.h:455:9`!('\\')); |
| 65 | value.removecxx . . $ QString#remove(30270fe3985671e6).(QL1Ccxx . . $ `src/librssguard/definitions/definitions.h:455:9`!(':')); |
| 66 | value.removecxx . . $ QString#remove(30270fe3985671e6).(QL1Ccxx . . $ `src/librssguard/definitions/definitions.h:455:9`!('*')); |
| 67 | value.removecxx . . $ QString#remove(30270fe3985671e6).(QL1Ccxx . . $ `src/librssguard/definitions/definitions.h:455:9`!('?')); |
| 68 | value.removecxx . . $ QString#remove(30270fe3985671e6).(QL1Ccxx . . $ `src/librssguard/definitions/definitions.h:455:9`!('"')); |
| 69 | value.removecxx . . $ QString#remove(30270fe3985671e6).(QL1Ccxx . . $ `src/librssguard/definitions/definitions.h:455:9`!('<')); |
| 70 | value.removecxx . . $ QString#remove(30270fe3985671e6).(QL1Ccxx . . $ `src/librssguard/definitions/definitions.h:455:9`!('>')); |
| 71 | value.removecxx . . $ QString#remove(30270fe3985671e6).(QL1Ccxx . . $ `src/librssguard/definitions/definitions.h:455:9`!('|')); |
| 72 | return valuecxx . . $ QString#QString(28715ad661ad3cec).; |
| 73 | } |
| 74 | |
| 75 | bool IOFactorycxx . . $ IOFactory#::startProcessDetachedcxx . . $ IOFactory#startProcessDetached(dc92d07c7f5866a0).(const QStringcxx . . $ QString#& executable, |
| 76 | const QStringListcxx . . $ QStringList#& arguments, |
| 77 | const QStringcxx . . $ QString#& working_directory) { |
| 78 | QProcesscxx . . $ QProcess# processcxx . . $ QProcess#QProcess(749de1b6ae65bddd).; |
| 79 | |
| 80 | process.setProgramcxx . . $ QProcess#setProgram(3520e46b33348bf6).(executable); |
| 81 | process.setArgumentscxx . . $ QProcess#setArguments(4c9f0945b8b27034).(arguments); |
| 82 | process.setWorkingDirectorycxx . . $ QProcess#setWorkingDirectory(3520e46b33348bf6).(working_directory); |
| 83 | |
| 84 | return process.startDetachedcxx . . $ QProcess#startDetached(c8e4b6cd00890e28).(nullptr); |
| 85 | } |
| 86 | |
| 87 | void IOFactorycxx . . $ IOFactory#::startProcesscxx . . $ IOFactory#startProcess(d450598c3919f783).(QProcesscxx . . $ QProcess#* const proc, |
| 88 | const QStringcxx . . $ QString#& executable, |
| 89 | const QStringListcxx . . $ QStringList#& arguments, |
| 90 | const QProcessEnvironmentcxx . . $ QProcessEnvironment#& pe, |
| 91 | const QStringcxx . . $ QString#& working_directory) { |
| 92 | proc->setProgramcxx . . $ QProcess#setProgram(3520e46b33348bf6).(executable); |
| 93 | proc->setArgumentscxx . . $ QProcess#setArguments(4c9f0945b8b27034).(arguments); |
| 94 | |
| 95 | QProcessEnvironmentcxx . . $ QProcessEnvironment# system_pe = QProcessEnvironmentcxx . . $ QProcessEnvironment#::systemEnvironmentcxx . . $ QProcessEnvironment#systemEnvironment(f0e8295e01d32d01).(); |
| 96 | |
| 97 | system_pe.insertcxx . . $ QProcessEnvironment#insert(6d5c9e1d6435e06a).(pe); |
| 98 | proc->setProcessEnvironmentcxx . . $ QProcess#setProcessEnvironment(6d5c9e1d6435e06a).(system_pe); |
| 99 | |
| 100 | if (!working_directory.isEmptycxx . . $ QString#isEmpty(3482b152b9333168).()) { |
| 101 | proc->setWorkingDirectorycxx . . $ QProcess#setWorkingDirectory(3520e46b33348bf6).(working_directory); |
| 102 | } |
| 103 | |
| 104 | proc->startcxx . . $ QProcess#start(677e99248c02e04d).(); |
| 105 | } |
| 106 | |
| 107 | QStringcxx . . $ QString# IOFactorycxx . . $ IOFactory#::startProcessGetOutputcxx . . $ IOFactory#startProcessGetOutput(ea321589343e1f82).(const QStringcxx . . $ QString#& executable, |
| 108 | const QStringListcxx . . $ QStringList#& arguments, |
| 109 | const QProcessEnvironmentcxx . . $ QProcessEnvironment#& pe, |
| 110 | const QStringcxx . . $ QString#& working_directory) { |
| 111 | QProcesscxx . . $ QProcess# proccxx . . $ QProcess#QProcess(749de1b6ae65bddd).; |
| 112 | |
| 113 | proc.setProgramcxx . . $ QProcess#setProgram(3520e46b33348bf6).(executable); |
| 114 | proc.setArgumentscxx . . $ QProcess#setArguments(4c9f0945b8b27034).(arguments); |
| 115 | |
| 116 | QProcessEnvironmentcxx . . $ QProcessEnvironment# system_pe = QProcessEnvironmentcxx . . $ QProcessEnvironment#::systemEnvironmentcxx . . $ QProcessEnvironment#systemEnvironment(f0e8295e01d32d01).(); |
| 117 | |
| 118 | system_pe.insertcxx . . $ QProcessEnvironment#insert(6d5c9e1d6435e06a).(pe); |
| 119 | proc.setProcessEnvironmentcxx . . $ QProcess#setProcessEnvironment(6d5c9e1d6435e06a).(system_pe); |
| 120 | |
| 121 | if (!working_directory.isEmptycxx . . $ QString#isEmpty(3482b152b9333168).()) { |
| 122 | proc.setWorkingDirectorycxx . . $ QProcess#setWorkingDirectory(3520e46b33348bf6).(working_directory); |
| 123 | } |
| 124 | |
| 125 | proc.startcxx . . $ QProcess#start(677e99248c02e04d).(); |
| 126 | |
| 127 | if (proc.waitForFinishedcxx . . $ QProcess#waitForFinished(83c267b20bac841a).() && proc.exitStatuscxx . . $ QProcess#exitStatus(15ed2eeed4841e77).() == QProcesscxx . . $ QProcess#::ExitStatuscxx . . $ QProcess#ExitStatus#::NormalExitcxx . . $ QProcess#NormalExit. && |
| 128 | proc.exitCodecxx . . $ QProcess#exitCode(455f465bc33b4cdf).() == EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!) { |
| 129 | return proccxx . . $ QString#QString(45672f3c6961a244)..readAllStandardOutputcxx . . $ QProcess#readAllStandardOutput(b3c286cec66e09f4).(); |
| 130 | } |
| 131 | else { |
| 132 | QStringcxx . . $ QString# err_output = proccxx . . $ QString#QString(45672f3c6961a244)..readAllStandardErrorcxx . . $ QProcess#readAllStandardError(b3c286cec66e09f4).().simplifiedcxx . . $ QByteArray#simplified(7c2073558a834e49).(); |
| 133 | |
| 134 | throw ProcessExceptioncxx . . $ ProcessException#ProcessException(8fa8a9db6e1dd7cb).(proc.exitCodecxx . . $ QProcess#exitCode(455f465bc33b4cdf).(), |
| 135 | proc.exitStatuscxx . . $ QProcess#exitStatus(15ed2eeed4841e77).(), |
| 136 | proc.errorcxx . . $ QProcess#error(e2b31e94b850a4d7).(), |
| 137 | err_output.isEmptycxx . . $ QString#isEmpty(3482b152b9333168).() ? proc.errorStringcxx . . $ QIODevice#errorString(6ef7b6c27b00b43d).() : err_outputcxx . . $ QString#QString(132dd6869045752b).); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | QByteArraycxx . . $ QByteArray# IOFactorycxx . . $ IOFactory#::readFilecxx . . $ IOFactory#readFile(743b31b35d83e992).(const QStringcxx . . $ QString#& file_path) { |
| 142 | QFilecxx . . $ QFile# input_filecxx . . $ QFile#QFile(3520e46b33348bf6).(file_path); |
| 143 | QByteArraycxx . . $ QByteArray# input_datacxx . . $ QByteArray#QByteArray(ced63f7c635d850d).; |
| 144 | |
| 145 | if (input_file.opencxx . . $ QFile#open(da34f43c1eae080c).(QIODevicecxx . . $ QIODevice#::Textcxx . . $ QIODeviceBase#Text. |cxx . . $ `operator|`(64b8367948668350). QIODevicecxx . . $ QIODevice#::Unbufferedcxx . . $ QIODeviceBase#Unbuffered. |cxx . . $ QFlags#`operator|`(2cc1994e0be6f18e). QIODevicecxx . . $ QIODevice#::ReadOnlycxx . . $ QIODeviceBase#ReadOnly.)) { |
| 146 | input_data =cxx . . $ QByteArray#`operator=`(c3d647c78c52d790). input_file.readAllcxx . . $ QIODevice#readAll(b3c286cec66e09f4).(); |
| 147 | input_file.closecxx . . $ QFileDevice#close(49f6e7a06ebc5aa8).(); |
| 148 | return input_datacxx . . $ QByteArray#QByteArray(9f1b912973d89fea).; |
| 149 | } |
| 150 | else { |
| 151 | throw IOExceptioncxx . . $ IOException#(trcxx . . $ IOFactory#tr(75d9f1c324b4579d).("Cannot open file '%1' for reading.").argcxx . . $ QString#arg(ad0bca07273edcc2).(QDircxx . . $ QDir#::toNativeSeparatorscxx . . $ QDir#toNativeSeparators(fd988a2ab94d906b).(file_path))); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | void IOFactorycxx . . $ IOFactory#::writeFilecxx . . $ IOFactory#writeFile(88f4c41ca0e941aa).(const QStringcxx . . $ QString#& file_path, const QByteArraycxx . . $ QByteArray#& data) { |
| 156 | QFilecxx . . $ QFile# input_filecxx . . $ QFile#QFile(3520e46b33348bf6).(file_path); |
| 157 | |
| 158 | if (input_file.opencxx . . $ QFile#open(da34f43c1eae080c).(QIODevicecxx . . $ QFlags#QFlags(93d577a3e9528307).::WriteOnlycxx . . $ QIODeviceBase#WriteOnly.)) { |
| 159 | input_file.writecxx . . $ QIODevice#write(4ee2750a0be83987).(data); |
| 160 | input_file.closecxx . . $ QFileDevice#close(49f6e7a06ebc5aa8).(); |
| 161 | } |
| 162 | else { |
| 163 | throw IOExceptioncxx . . $ IOException#(trcxx . . $ IOFactory#tr(75d9f1c324b4579d).("Cannot open file '%1' for writting.").argcxx . . $ QString#arg(ad0bca07273edcc2).(QDircxx . . $ QDir#::toNativeSeparatorscxx . . $ QDir#toNativeSeparators(fd988a2ab94d906b).(file_path))); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | bool IOFactorycxx . . $ IOFactory#::copyFilecxx . . $ IOFactory#copyFile(edf9e4f73813982f).(const QStringcxx . . $ QString#& source, const QStringcxx . . $ QString#& destination) { |
| 168 | if (QFilecxx . . $ QFile#::existscxx . . $ QFile#exists(e1defb592416720d).(destination)) { |
| 169 | QFilecxx . . $ QFile# filecxx . . $ QFile#QFile(3520e46b33348bf6).(destination); |
| 170 | |
| 171 | file.setPermissionscxx . . $ QFile#setPermissions(1c993c9c93edeab).(file.permissionscxx . . $ QFile#permissions(82176f88d78e622a).() |cxx . . $ QFlags#`operator|`(2cc1994e0be6f18e). QFileDevicecxx . . $ QFileDevice#::WriteOwnercxx . . $ QFileDevice#WriteOwner. |cxx . . $ QFlags#`operator|`(2cc1994e0be6f18e). QFileDevicecxx . . $ QFileDevice#::WriteUsercxx . . $ QFileDevice#WriteUser. |cxx . . $ QFlags#`operator|`(2cc1994e0be6f18e). |
| 172 | QFileDevicecxx . . $ QFileDevice#::WriteGroupcxx . . $ QFileDevice#WriteGroup. |cxx . . $ QFlags#`operator|`(2cc1994e0be6f18e). QFileDevicecxx . . $ QFileDevice#::WriteOthercxx . . $ QFileDevice#WriteOther.); |
| 173 | |
| 174 | if (!QFilecxx . . $ QFile#::removecxx . . $ QFile#remove(e1defb592416720d).(destination)) { |
| 175 | return false; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | return QFilecxx . . $ QFile#::copycxx . . $ QFile#copy(edf9e4f73813982f).(source, destination); |
| 180 | } |
| 181 | |
| 182 | void IOFactorycxx . . $ IOFactory#::removeFoldercxx . . $ IOFactory#removeFolder(3520e46b33348bf6).(const QStringcxx . . $ QString#& path) { |
| 183 | QDircxx . . $ QDir# dircxx . . $ QDir#QDir(3520e46b33348bf6).(path); |
| 184 | dir.removeRecursivelycxx . . $ QDir#removeRecursively(c9857a73d68e59ba).(); |
| 185 | } |