11#include < QtGui>
22#include " mainspinwindow.h"
3+ #include " quazip.h"
4+ #include " quazipfile.h"
5+ #include " directory.h"
36
47int main (int argc, char *argv[])
58{
@@ -32,7 +35,6 @@ int main(int argc, char *argv[])
3235 QLibraryInfo::location (QLibraryInfo::TranslationsPath));
3336 a.installTranslator (&qTranslator);
3437
35- QTranslator qtTranslator;
3638 QString progName = QString (ASideGuiKey)+" _" ;
3739
3840 qDebug () << " Locale: " ;
@@ -42,6 +44,7 @@ int main(int argc, char *argv[])
4244 * according to QTranslator::load, this will pick up:
4345 * foo_en_us.qm, foo_en.qm, foo_zh_SG.qm, foo_zh_TW.qm or foo_zh.qm
4446 */
47+ QTranslator qtTranslator;
4548 if (qtTranslator.load (progName + QLocale::system ().name (), transpath)) {
4649 qDebug () << " Translating ..." ;
4750 a.installTranslator (&qtTranslator);
@@ -56,11 +59,89 @@ int main(int argc, char *argv[])
5659
5760 if (argc > 1 ) {
5861 QString s = QString (argv[1 ]);
59- if (s.contains (QDir::toNativeSeparators (QDir::tempPath ())) &&
60- s.contains (" .zip" ,Qt::CaseInsensitive)) {
61- QMessageBox::critical (&w, w.tr (" Cannot Open from Zip" ),
62- w.tr (" The file is in a zipped archive. Unzip to" )+" \n " +
63- w.tr (" a folder first, and open from there instead." ));
62+ if (s.contains (" .zip" ,Qt::CaseInsensitive)) {
63+ int rc;
64+ QString sname = s;
65+ QRegExp rz (" .zip" , Qt::CaseInsensitive);
66+ int end = sname.lastIndexOf (rz);
67+ end += 4 ;
68+ QString zipname = s.mid (end+1 );
69+ zipname = zipname.trimmed ();
70+ sname = sname.mid (0 ,end);
71+ QuaZip zip (sname);
72+ zip.open (QuaZip::mdUnzip);
73+ rc = zip.getZipError ();
74+ if (rc | (zipname.length () == 0 ) ) {
75+ QMessageBox::critical (&w, w.tr (" Cannot Open from Zip" ),
76+ w.tr (" The file is in a zipped archive. Unzip to" )+" \n " +
77+ w.tr (" a folder first, and open from there instead." ));
78+ }
79+ else {
80+ QStringList files = zip.getFileNameList ();
81+ QString tmpfolder = QDir::tempPath ()+" /SimpleIDE" ;
82+ if (files.count () > 0 ) {
83+ QDir dir (tmpfolder);
84+ if (QFile::exists (tmpfolder))
85+ Directory::recursiveRemoveDir (tmpfolder);
86+ dir.mkdir (tmpfolder);
87+ }
88+ #if 0
89+ foreach (QString file, files) {
90+ zip.getCurrentFileName(file);
91+ }
92+ #endif
93+ QuaZipFile file (&zip);
94+ bool f =zip.goToFirstFile ();
95+ for (; f; f=zip.goToNextFile ()) {
96+ QuaZipFileInfo info;
97+ file.getFileInfo (&info);
98+ if (info.name .length () == 0 )
99+ continue ;
100+ QString name = info.name ;
101+ QStringList folders = name.split (" /" );
102+
103+ QString path = tmpfolder;
104+ for (int n = 0 ; n < folders.count ()-1 ; n++) {
105+ path += " /" + folders[n];
106+ QDir dir (path);
107+ if (QFile::exists (path) == false )
108+ dir.mkdir (path);
109+ }
110+
111+ QFile newFile (tmpfolder+" /" +info.name );
112+ file.open (QIODevice::ReadOnly);
113+ newFile.open (QIODevice::WriteOnly);
114+ QTextStream outToFile (&newFile);
115+ outToFile << file.readAll ();;
116+ newFile.close ();
117+ file.close ();
118+ }
119+ zip.close ();
120+
121+ w.closeProject ();
122+ QString filename = tmpfolder+" /" +zipname;
123+ if (filename.endsWith (" .c" ) ||
124+ filename.endsWith (" .cpp" ) ||
125+ filename.endsWith (" .cogc" ) ||
126+ filename.endsWith (" .h" ) ||
127+ filename.endsWith (" .spin" )) {
128+ w.openFile (tmpfolder+" /" +zipname);
129+ }
130+ /*
131+ * Disallow .side projects or other file names for now.
132+ */
133+ else if (filename.endsWith (" .side" )) {
134+ QMessageBox::critical (&w, w.tr (" Cannot Open Projects from Zip" ),
135+ w.tr (" The project is in a zipped archive. Unzip to" )+" \n " +
136+ w.tr (" a folder first, and open from there instead." ));
137+ }
138+ else {
139+ // w.openFile(tmpfolder+"/"+zipname+"/"+zipname+".side");
140+ QMessageBox::critical (&w, w.tr (" Cannot Open from Zip" ),
141+ w.tr (" The file is in a zipped archive. Unzip to" )+" \n " +
142+ w.tr (" a folder first, and open from there instead." ));
143+ }
144+ }
64145 }
65146 else {
66147 s = s.mid (s.lastIndexOf (" ." ));
0 commit comments