- commit work done on projects projects

Wed, 04 Mar 2015 15:37:21 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Wed, 04 Mar 2015 15:37:21 +0200
branch
projects
changeset 936
aee883858c90
parent 935
8d98ee0dc917
child 937
d5a58674ccd1

- commit work done on projects

CMakeLists.txt file | annotate | diff | comparison | revisions
src/ldproject.cpp file | annotate | diff | comparison | revisions
src/ldproject.h file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Tue Mar 03 22:29:27 2015 +0200
+++ b/CMakeLists.txt	Wed Mar 04 15:37:21 2015 +0200
@@ -50,6 +50,7 @@
 	src/ldDocument.cpp
 	src/ldObject.cpp
 	src/ldObjectMath.cpp
+	src/ldproject.cpp
 	src/main.cpp
 	src/mainWindow.cpp
 	src/messageLog.cpp
@@ -149,6 +150,7 @@
 	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -DQ_COMPILER_INITIALIZER_LISTS")
 endif()
 
+include_directories (${LibArchive_INCLUDE_DIRS})
 include_directories ("${PROJECT_BINARY_DIR}")
 include_directories ("${PROJECT_BINARY_DIR}/src")
 include_directories ("${PROJECT_BINARY_DIR}/src/misc")
@@ -174,7 +176,13 @@
 endif()
 
 if (USE_QT5)
-	target_link_libraries (${PROJECT_NAME} Qt5::Widgets Qt5::Network Qt5::OpenGL ${OPENGL_LIBRARIES})
+	target_link_libraries (${PROJECT_NAME}
+		Qt5::Widgets
+		Qt5::Network
+		Qt5::OpenGL
+		${OPENGL_LIBRARIES}
+		${LibArchive_LIBRARIES}
+	)
 else()
 	target_link_libraries (${PROJECT_NAME}
 		${QT_QTCORE_LIBRARY}
@@ -182,6 +190,7 @@
 		${QT_QTNETWORK_LIBRARY}
 		${QT_QTOPENGL_LIBRARY}
 		${OPENGL_LIBRARIES}
+		${LibArchive_LIBRARIES}
 	)
 endif()
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ldproject.cpp	Wed Mar 04 15:37:21 2015 +0200
@@ -0,0 +1,75 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2013 - 2015 Teemu Piippo
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <archive.h>
+#include <archive_entry.h>
+#include "ldproject.h"
+
+LDProject::LDProject() {}
+LDProject::~LDProject() {}
+
+LDProjectPtr LDProject::LoadFromFile (const QString& filename)
+{
+	FILE* fp = fopen ("log.txt", "w");
+	if (!fp)
+		return LDProjectPtr();
+
+	archive* arc = archive_read_new();
+	archive_read_support_filter_all (arc);
+	archive_read_support_format_all (arc);
+	// archive_read_support_format_zip (arc);
+	archive_entry* arcent;
+	int result = archive_read_open_filename (arc, filename.toLocal8Bit().constData(), 0x4000);
+
+	if (result != ARCHIVE_OK)
+	{
+		fprint (fp, "unable to open argh.pk3 (%1)\n", archive_error_string (arc));
+		return LDProjectPtr();
+	}
+
+	while (archive_read_next_header(arc, &arcent) == ARCHIVE_OK)
+	{
+		QString pathname = archive_entry_pathname (arcent);
+		char buffer[1024];
+		int size = archive_read_data(arc, buffer, sizeof buffer);
+
+		if (size < 0)
+			fprint (fp, "Error reading entry %1: %2", pathname, archive_error_string (arc));
+		else
+			fprint (fp, "%1 contains: %2 (%3 bytes)\n", pathname, static_cast<const char*>(buffer), size);
+	}
+
+	if ((result = archive_read_free(arc)) != ARCHIVE_OK)
+	{
+		fprint (fp, "unable to close argh.pk3\n");
+		return LDProjectPtr();
+	}
+
+	return LDProjectPtr();
+}
+
+LDProjectPtr LDProject::NewProject()
+{
+	return LDProjectPtr (new LDProject());
+}
+
+bool LDProject::save (const QString &filename)
+{
+	return false;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ldproject.h	Wed Mar 04 15:37:21 2015 +0200
@@ -0,0 +1,23 @@
+#pragma once
+#include "main.h"
+
+using LDProjectPtr = QSharedPointer<class LDProject>;
+
+class LDProject
+{
+public:
+	LDProject (const LDProject&) = delete;
+	~LDProject();
+
+	bool save (const QString& filename);
+
+	void operator= (const LDProject&) = delete;
+	static LDProjectPtr LoadFromFile (const QString& filename);
+	static LDProjectPtr NewProject();
+
+private:
+	QString m_filePath;
+	QList<LDDocumentPtr> m_documents;
+	LDProject();
+};
+
--- a/src/main.cpp	Tue Mar 03 22:29:27 2015 +0200
+++ b/src/main.cpp	Wed Mar 04 15:37:21 2015 +0200
@@ -42,12 +42,18 @@
 const Matrix IdentityMatrix ({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f});
 
 CFGENTRY (Bool, FirstStart, true)
+#include "ldproject.h"
 
 // =============================================================================
 //
 int main (int argc, char* argv[])
 {
 	QApplication app (argc, argv);
+
+	LDProjectPtr proj = LDProject::LoadFromFile("argh.pk3");
+	if (!proj)
+		Critical ("Couldn't open argh.pk3");
+	return 0;
 	app.setOrganizationName (APPNAME);
 	app.setApplicationName (APPNAME);
 	InitCrashCatcher();

mercurial