Skip to content

Commit

Permalink
remove doc readonly remove isTextFile
Browse files Browse the repository at this point in the history
  • Loading branch information
winsvega committed Feb 18, 2016
1 parent 51afbe3 commit 3a2ef8b
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 70 deletions.
7 changes: 0 additions & 7 deletions qml/WebCodeEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,6 @@ Item {
{
setText("File size is too large!", currentMode);
setReadOnly(true);
document.readOnly = true;
}
else if (!fileIo.isFileText(document.path))
{
setText("Can't read binary file!", currentMode);
setReadOnly(true);
document.readOnly = true;
}
else
setText(currentText, currentMode);
Expand Down
1 change: 0 additions & 1 deletion qml/js/ProjectModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ function file(docData)
var groupName = isContract ? qsTr("Contracts") : isJs ? qsTr("Javascript") : isHtml ? qsTr("Web Pages") : isCss ? qsTr("Styles") : isImg ? qsTr("Images") : qsTr("Misc");
var docData = {
contract: false,
readOnly: false,
path: path,
fileName: fileName,
name: fileName,
Expand Down
60 changes: 0 additions & 60 deletions src/FileIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,66 +183,6 @@ int FileIo::getFileSize(QString const& _url)
return 0;
}

bool FileIo::isFileText(QString const& _url)
{
try
{
QString path = pathFromUrl(_url);
QFile file(path);
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QByteArray buf = file.read(file.bytesAvailable());

if (buf.size() >= 2)
{
//FF FE UTF - 16, little endian
if ((quint8)buf[0] == 0xFF && (quint8)buf[1] == 0xFE)
return true;

//FE FF UTF - 16, big endian
if ((quint8)buf[0] == 0xFE && (quint8)buf[1] == 0xFF)
return true;
}

if (buf.size() >= 3)
{
//EF BB BF UTF - 8
if ((quint8)buf[0] == 0xEF && (quint8)buf[1] == 0xBB && (quint8)buf[2] == 0xBF)
return true;
}

if (buf.size() >= 4)
{
//FF FE 00 00 UTF - 32, little endian
if ((quint8)buf[0] == 0xFF && (quint8)buf[1] == 0xFE && (quint8)buf[2] == 0x00 && (quint8)buf[3] == 0x00)
return true;

//00 00 FE FF UTF - 32, big - endian
if ((quint8)buf[0] == 0x00 && (quint8)buf[1] == 0x00 && (quint8)buf[2] == 0xFE && (quint8)buf[3] == 0xFF)
return true;
}

int checkLength = std::min(buf.size(), 1024000);
for (int i = 0; i < checkLength; i++)
{
if (!isascii(buf[i]) ||
(iscntrl(buf[i]) && !isspace(buf[i]) &&
buf[i] != '\b' && buf[i] != '\032' && buf[i] != '\033'))
return false; /* not all ASCII */
}
return true;
}
else
error(tr("Error reading file %1").arg(_url));
}
catch (...)
{
manageException();
}

return false;
}

void FileIo::writeFile(QString const& _url, QString const& _data)
{
try
Expand Down
2 changes: 0 additions & 2 deletions src/FileIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class FileIo: public QObject
Q_INVOKABLE QString readFile(QString const& _url);
/// Returns file size
Q_INVOKABLE int getFileSize(QString const& _url);
/// Is file represent readable text
Q_INVOKABLE bool isFileText(QString const& _url);
/// Write contents to a file. Signals on failure.
Q_INVOKABLE void writeFile(QString const& _url, QString const& _data);
/// Copy a file from _sourcePath to _destPath. Signals on failure.
Expand Down

0 comments on commit 3a2ef8b

Please sign in to comment.