-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RELEASE v0.1.1] Release Spirit v0.1.1 (bugfix)
- Loading branch information
Showing
7 changed files
with
153 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef BASHRC_WRITER_HPP_INCLUDED | ||
#define BASHRC_WRITER_HPP_INCLUDED | ||
#include <QString> | ||
|
||
class BashRCWriter { | ||
public: | ||
BashRCWriter(); | ||
~BashRCWriter(); | ||
|
||
void setProgram(const QString&); | ||
bool write(); | ||
bool unwrite(); | ||
private: | ||
QString m_Program; | ||
}; | ||
|
||
#endif // BASHRC_WRITER_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Spirit v0.1.1 | ||
|
||
* Fixed .bashrc writer to be more robust. | ||
* Avoid invalid code written to .bashrc | ||
* Fixed applicationFilePath() for **AppImage**. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include <QDir> | ||
#include <QFile> | ||
#include <QTextStream> | ||
#include <QStringList> | ||
|
||
#include "bashrcwriter.hpp" | ||
|
||
static bool writeContents(const QString &bashrc, const QStringList &contents) { | ||
QFile file(bashrc); | ||
if(!file.open(QIODevice::WriteOnly | QIODevice::Text)){ | ||
return false; | ||
} | ||
file.seek(0); | ||
QTextStream out(&file); | ||
|
||
for(auto line : contents) { | ||
out << line; | ||
} | ||
file.close(); | ||
return true; | ||
} | ||
|
||
BashRCWriter::BashRCWriter() { } | ||
BashRCWriter::~BashRCWriter() { } | ||
|
||
void BashRCWriter::setProgram(const QString &value) { | ||
m_Program = value; | ||
} | ||
|
||
bool BashRCWriter::write() { | ||
if(m_Program.isEmpty()) { | ||
return false; | ||
} | ||
QString comment = QString::fromUtf8("### spirit trap commands\n"); | ||
QString trap_line = QString::fromUtf8("trap \"%1 %2\" %3\n"); | ||
const QString bashrc = QDir::homePath() + QDir::separator() + ".bashrc"; | ||
|
||
QFile file(bashrc); | ||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ | ||
return false; | ||
} | ||
|
||
file.seek(0); | ||
|
||
QStringList contents; | ||
bool appended = false; | ||
while(!file.atEnd()) { | ||
auto line = file.readLine(); | ||
if(line.contains("### spirit trap commands")) { | ||
contents << comment; | ||
contents << trap_line.arg(m_Program).arg("error").arg("ERR"); | ||
contents << trap_line.arg(m_Program).arg("nonerror").arg("DEBUG"); | ||
|
||
/// Go past two lines | ||
line = file.readLine(); | ||
line = file.readLine(); | ||
|
||
appended = true; | ||
}else { | ||
contents << line; | ||
} | ||
} | ||
|
||
if(!appended) { | ||
contents << comment; | ||
contents << trap_line.arg(m_Program).arg("error").arg("ERR"); | ||
contents << trap_line.arg(m_Program).arg("nonerror").arg("DEBUG"); | ||
} | ||
file.close(); | ||
|
||
return writeContents(bashrc, contents); | ||
} | ||
|
||
bool BashRCWriter::unwrite() { | ||
if(m_Program.isEmpty()) { | ||
return false; | ||
} | ||
|
||
const QString bashrc = QDir::homePath() + QDir::separator() + ".bashrc"; | ||
QFile file(bashrc); | ||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ | ||
return false; | ||
} | ||
|
||
file.seek(0); | ||
|
||
QStringList contents; | ||
while(!file.atEnd()) { | ||
auto line = file.readLine(); | ||
if(line.contains("### spirit trap commands")) { | ||
/// Go past two lines | ||
line = file.readLine(); | ||
line = file.readLine(); | ||
}else { | ||
contents << line; | ||
} | ||
} | ||
file.close(); | ||
|
||
return writeContents(bashrc, contents); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters