def saveTextdata(self, filePath, data): outFile = QFileInfo(filePath) fileName = outFile.fileName() if QFile.exists(fileName): QFile.remove(fileName) outFile = QFile(outFile.absoluteFilePath()) outFile.open(QIODevice.WriteOnly | QIODevice.Text) if outFile.error() != outFile.NoError: self.msgBox.information( QDialog().move(self.fly), "{}".format(fileName), self.translate("openV2rayJSONFile", "Unable to open the file {}: {}.").format( fileName, outFile.errorString())) outFile = None return False outFile.write(codecs.encode(data, "utf-8")) if outFile.error() != outFile.NoError: self.msgBox.information( QDialog().move(self.fly), "{}".format(fileName), self.translate("openV2rayJSONFile", "Unable to save the file {}: {}.").format( fileName, outFile.errorString())) outFile = None return False outFile.close()
def saveV2raycoreJSONFile(self): JSONData = {} JSONData["preferences"] = copy.deepcopy(self.preferences) JSONData["update"] = copy.deepcopy(self.update) JSONData["configFiles"] = copy.deepcopy(self.configFiles) outFile = QFileInfo(self.v2rayshellConfigFileName) fileName = outFile.fileName() if QFile.exists(fileName): QFile.remove(fileName) outFile = QFile(fileName) outFile.open(QIODevice.WriteOnly | QIODevice.Text) if outFile.error() != outFile.NoError: self.msgBox.information(QDialog().move(self.fly), "{}".format(fileName), self.translate("bridgetreasureChest", "Unable to open the file {}: {}.").format(fileName, outFile.errorString())) outFile = None return False outFile.write(codecs.encode(json.dumps(JSONData, indent = 4, sort_keys = False), "utf-8")) if outFile.error() != outFile.NoError: self.msgBox.information(QDialog().move(self.fly), "{}".format(fileName), self.translate("bridgetreasureChest", "Unable to save the file {}: {}.").format(fileName, outFile.errorString())) outFile = None return False outFile.close()
def savebugReportText(self, save=False): if save: outFile = QFileInfo(self.translate("bugReport", "bugReport.txt")) fileName = outFile.fileName() if QFile.exists(fileName): QFile.remove(fileName) outFile = QFile(fileName) outFile.open(QIODevice.WriteOnly | QIODevice.Text) outFile.write(codecs.encode(save, "utf-8"))
def oncreatePIDFile(self): if self.v2rayProcess.state() == QProcess.NotRunning: return outFile = QFileInfo(self.pidFile) fileName = outFile.fileName() if QFile.exists(fileName): QFile.remove(fileName) outFile = QFile(fileName) v2rayPID = str(self.v2rayProcess.processId()) qDebug("process ID is: {}".format(v2rayPID)) try: outFile.open(QIODevice.WriteOnly | QIODevice.Text) outFile.write(codecs.encode(v2rayPID, "utf-8")) except Exception: pass outFile.close()
def killOrphanProcess(self): openFile = QFileInfo(self.pidFile) fileName = openFile.fileName() if QFile.exists(fileName): openFile = QFile(fileName) else: return v2rayPID = None try: openFile.open(QIODevice.ReadOnly | QIODevice.Text) v2rayPID = str(openFile.readAll(), "utf-8") except Exception: pass try: os.kill(int(v2rayPID), signal.SIGTERM) except Exception: pass
def createStartupFile(self, autostartupPath, scriptName, script, enable=False): fileName = os.path.join(autostartupPath, scriptName) outFile = QFileInfo(fileName) if QFile.exists(fileName): QFile.remove(fileName) if not enable: return True outFile = QFile(fileName) outFile.open(QIODevice.WriteOnly | QIODevice.Text) if outFile.error() != outFile.NoError: outFile = None return False outFile.write(codecs.encode(script, "utf-8")) if outFile.error() != outFile.NoError: outFile = None return False outFile.close() return True