src/ldproject.cpp

branch
projects
changeset 936
aee883858c90
child 937
d5a58674ccd1
equal deleted inserted replaced
935:8d98ee0dc917 936:aee883858c90
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013 - 2015 Teemu Piippo
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <archive.h>
20 #include <archive_entry.h>
21 #include "ldproject.h"
22
23 LDProject::LDProject() {}
24 LDProject::~LDProject() {}
25
26 LDProjectPtr LDProject::LoadFromFile (const QString& filename)
27 {
28 FILE* fp = fopen ("log.txt", "w");
29 if (!fp)
30 return LDProjectPtr();
31
32 archive* arc = archive_read_new();
33 archive_read_support_filter_all (arc);
34 archive_read_support_format_all (arc);
35 // archive_read_support_format_zip (arc);
36 archive_entry* arcent;
37 int result = archive_read_open_filename (arc, filename.toLocal8Bit().constData(), 0x4000);
38
39 if (result != ARCHIVE_OK)
40 {
41 fprint (fp, "unable to open argh.pk3 (%1)\n", archive_error_string (arc));
42 return LDProjectPtr();
43 }
44
45 while (archive_read_next_header(arc, &arcent) == ARCHIVE_OK)
46 {
47 QString pathname = archive_entry_pathname (arcent);
48 char buffer[1024];
49 int size = archive_read_data(arc, buffer, sizeof buffer);
50
51 if (size < 0)
52 fprint (fp, "Error reading entry %1: %2", pathname, archive_error_string (arc));
53 else
54 fprint (fp, "%1 contains: %2 (%3 bytes)\n", pathname, static_cast<const char*>(buffer), size);
55 }
56
57 if ((result = archive_read_free(arc)) != ARCHIVE_OK)
58 {
59 fprint (fp, "unable to close argh.pk3\n");
60 return LDProjectPtr();
61 }
62
63 return LDProjectPtr();
64 }
65
66 LDProjectPtr LDProject::NewProject()
67 {
68 return LDProjectPtr (new LDProject());
69 }
70
71 bool LDProject::save (const QString &filename)
72 {
73 return false;
74 }
75

mercurial