Browse Source

small changes

cl-refactor
yann300 10 years ago
parent
commit
92866a5150
  1. 39
      mix/FileIo.cpp
  2. 2
      mix/FileIo.h
  3. 15
      mix/qml/DeploymentDialog.qml
  4. 2
      mix/qml/ProjectModel.qml
  5. 4
      mix/qml/js/ProjectModel.js

39
mix/FileIo.cpp

@ -20,8 +20,6 @@
* Ethereum IDE client. * Ethereum IDE client.
*/ */
#include <QJsonObject>
#include <QDebug>
#include <QDirIterator> #include <QDirIterator>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
@ -112,7 +110,7 @@ bool FileIo::fileExists(QString const& _url)
return file.exists(); return file.exists();
} }
QStringList FileIo::compress(QString const& _deploymentFolder) QStringList FileIo::makePackage(QString const& _deploymentFolder)
{ {
Json::Value manifest; Json::Value manifest;
@ -124,42 +122,37 @@ QStringList FileIo::compress(QString const& _deploymentFolder)
dev::RLPStream str; dev::RLPStream str;
int k = 1; int k = 1;
QMap<std::string, bytesConstRef> files;
for (auto item: deployDir.entryInfoList(QDir::Files)) for (auto item: deployDir.entryInfoList(QDir::Files))
{ {
QFile qFile(item.filePath()); QFile qFile(item.filePath());
if (qFile.open(QIODevice::ReadOnly | QIODevice::Text)) if (qFile.open(QIODevice::ReadOnly))
k++;
}
str.appendList(k);
for (auto item: deployDir.entryInfoList(QDir::Files))
{
QFile qFile(item.filePath());
if (qFile.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
k++;
QFileInfo i = QFileInfo(qFile.fileName()); QFileInfo i = QFileInfo(qFile.fileName());
QByteArray _a = qFile.readAll();
bytes b = bytes(_a.begin(), _a.end());
str.append(b);
Json::Value f; Json::Value f;
f["path"] = "/"; //TODO: Manage relative sub folder std::string path = i.fileName() == "index.html" ? "/" : i.fileName().toStdString();
f["path"] = path; //TODO: Manage relative sub folder
f["file"] = "/" + i.fileName().toStdString(); f["file"] = "/" + i.fileName().toStdString();
f["contentType"] = "application/html"; //TODO: manage multiple content type f["contentType"] = "text/html"; //TODO: manage multiple content type
f["hash"] = toHex(dev::sha3(b).ref()); QByteArray _a = qFile.readAll();
files.insert(path, bytesConstRef((const unsigned char*)_a.data(), _a.size()));
f["hash"] = toHex(dev::sha3(files.value(path)).ref());
entries.append(f); entries.append(f);
} }
qFile.close(); qFile.close();
} }
str.appendList(k);
manifest["entries"] = entries;
std::stringstream jsonStr; std::stringstream jsonStr;
jsonStr << manifest; jsonStr << manifest;
QByteArray b = QString::fromStdString(jsonStr.str()).toUtf8(); QByteArray b = QString::fromStdString(jsonStr.str()).toUtf8();
str.append(bytes(b.begin(), b.end())); str.append(bytesConstRef((const unsigned char*)b.data(), b.size()));
for (auto item: files.keys())
str.append(files.value(item));
manifest["entries"] = entries;
bytes dapp = str.out(); bytes dapp = str.out();
dev::h256 h = dev::sha3(dapp); dev::h256 h = dev::sha3(dapp);
//encrypt //encrypt

2
mix/FileIo.h

@ -54,7 +54,7 @@ public:
/// Check if file exists /// Check if file exists
Q_INVOKABLE bool fileExists(QString const& _url); Q_INVOKABLE bool fileExists(QString const& _url);
/// Compress a folder, @returns sha3 of the compressed file. /// Compress a folder, @returns sha3 of the compressed file.
Q_INVOKABLE QStringList compress(QString const& _deploymentFolder); Q_INVOKABLE QStringList makePackage(QString const& _deploymentFolder);
private: private:
QString getHomePath() const; QString getHomePath() const;

15
mix/qml/DeploymentDialog.qml

@ -110,17 +110,10 @@ Window {
anchors.right: parent.right; anchors.right: parent.right;
anchors.bottomMargin: 10 anchors.bottomMargin: 10
Button { Button {
text: qsTr("Deploy on Ethereum"); text: qsTr("Deploy to Ethereum");
tooltip: qsTr("Deploy the contract and Package ressources files.") tooltip: qsTr("Deploy contract and package resources files.")
onClicked: { onClicked: {
if (applicationUrlEth.text === "") deployWarningDialog.open();
{
deployDialog.title = text;
deployDialog.text = qsTr("Please provide the Ethereum link you want to use for this application.")
deployDialog.open();
}
else
deployWarningDialog.open();
} }
} }
@ -131,7 +124,7 @@ Window {
if (applicationUrlHttp.text === "" || deploymentDialog.packageHash === "") if (applicationUrlHttp.text === "" || deploymentDialog.packageHash === "")
{ {
deployDialog.title = text; deployDialog.title = text;
deployDialog.text = qsTr("Please provide the link where the ressources are stored and ensure the package is aleary built using the deployment step. ") deployDialog.text = qsTr("Please provide the link where the resources are stored and ensure the package is aleary built using the deployment step. ")
deployDialog.open(); deployDialog.open();
} }
else else

2
mix/qml/ProjectModel.qml

@ -101,7 +101,7 @@ Item {
{ {
redeploy = true redeploy = true
standardButtons = StandardButton.Ok | StandardButton.Reset | StandardButton.Abort; standardButtons = StandardButton.Ok | StandardButton.Reset | StandardButton.Abort;
return qsTr("This project has been already deployed to the network. Do you want to repackage the ressources only, or also reset the deployed contract to his initial state?") return qsTr("This project has been already deployed to the network. Do you want to repackage the resources only, or also reset the deployed contract to its initial state?")
} }
else else
{ {

4
mix/qml/js/ProjectModel.js

@ -390,7 +390,7 @@ function finalizeDeployment(deploymentId, addresses) {
deploymentAddresses = addresses; deploymentAddresses = addresses;
saveProject(); saveProject();
var packageRet = fileIo.compress(deploymentDir); var packageRet = fileIo.makePackage(deploymentDir);
deploymentDialog.packageHash = packageRet[0]; deploymentDialog.packageHash = packageRet[0];
deploymentDialog.packageBase64 = packageRet[1]; deploymentDialog.packageBase64 = packageRet[1];
@ -531,7 +531,7 @@ function checkRegistration(dappUrl, addr, callBack)
function registerToUrlHint() function registerToUrlHint()
{ {
deploymentStepChanged(qsTr("Registering application Ressources (" + deploymentDialog.applicationUrlHttp) + ") ..."); deploymentStepChanged(qsTr("Registering application Resources (" + deploymentDialog.applicationUrlHttp) + ") ...");
var requests = []; var requests = [];
var paramUrlHttp = createString(deploymentDialog.applicationUrlHttp); var paramUrlHttp = createString(deploymentDialog.applicationUrlHttp);
requests.push({ requests.push({

Loading…
Cancel
Save