@@ -12,10 +12,15 @@ extern QMainWindow* mainWindow;
1212
1313class ArchiveStorage {
1414public:
15+ QString config = " " ;
1516 void add (const QString& path, const QImage& image) {
1617 values[path] = image;
1718 }
1819
20+ void setConfig (QString cfg){
21+ config = cfg;
22+ }
23+
1924 void create (const QString& archiveFileName) {
2025 // Open the archive file
2126 struct archive * ar = archive_write_new ();
@@ -24,15 +29,14 @@ class ArchiveStorage {
2429 archive_write_open_filename (ar, archiveFileName.toStdString ().c_str ());
2530 // write config
2631 struct archive_entry * entry = archive_entry_new ();
27- QString config = QString::number (mainWindow->geometry ().width ()) + " x" + QString::number (mainWindow->geometry ().height ());
2832 archive_entry_set_pathname (entry, " config" );
2933 archive_entry_set_filetype (entry, AE_IFREG);
3034 archive_entry_set_perm (entry, 0644 );
3135 archive_entry_set_size (entry, config.size ());
3236 archive_write_header (ar, entry);
3337 archive_write_data (ar, config.toStdString ().c_str (), config.size ());
3438 archive_entry_free (entry);
35-
39+
3640 for (auto it = values.begin (); it != values.end (); ++it) {
3741 QString path = it.key ();
3842 QImage image = it.value ();
@@ -52,10 +56,12 @@ class ArchiveStorage {
5256 // Clean up
5357 archive_write_close (ar);
5458 archive_write_free (ar);
59+ values.clear ();
5560 }
5661
5762 QMap<QString, QImage> load (const QString& archiveFileName) {
5863 QMap<QString, QImage> values;
64+ config = " " ;
5965 // Open the archive file
6066 struct archive *ar;
6167 struct archive_entry *entry;
@@ -89,9 +95,16 @@ class ArchiveStorage {
8995 }
9096 printf (" Decompress:%s %ld\n " , entryName, total_size);
9197 if (strcmp (entryName, " config" ) == 0 ){
92- QStringList res = QString::fromUtf8 (*imageData).split (" x" );
93- width = res[0 ].toInt ();
94- height = res[1 ].toInt ();
98+ config = QString::fromUtf8 (*imageData);
99+ QStringList list = config.split (" \n " );
100+ for (const auto &str : std::as_const (list)) {
101+ if (str.startsWith (" width=" )){
102+ width = str.split (" =" )[1 ].toInt ();
103+ } else if (str.startsWith (" height=" )){
104+ height = str.split (" =" )[1 ].toInt ();
105+ }
106+
107+ }
95108 continue ;
96109 }
97110 QImage image = QImage (reinterpret_cast <const uchar*>(imageData->data ()), width, height, QImage::Format_ARGB32);
@@ -121,6 +134,13 @@ void archive_add(const QString& path, const QImage& image){
121134 archive.add (path, image);
122135}
123136
137+ void archive_set_config (const QString& cfg){
138+ archive.setConfig (cfg);
139+ }
140+ QString archive_get_config (){
141+ return archive.config ;
142+ }
143+
124144void archive_create (const QString& archiveFileName){
125145 archive.create (archiveFileName);
126146}
0 commit comments