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