Show an error message box when main file loading fails.

Mon, 22 Apr 2013 17:01:37 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 22 Apr 2013 17:01:37 +0300
changeset 130
ec4b30b166fe
parent 129
9cf313447c8f
child 131
3ccb10f6ed0b

Show an error message box when main file loading fails.

file.cpp file | annotate | diff | comparison | revisions
file.h file | annotate | diff | comparison | revisions
--- a/file.cpp	Mon Apr 22 16:43:01 2013 +0300
+++ b/file.cpp	Mon Apr 22 17:01:37 2013 +0300
@@ -109,13 +109,17 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-OpenFile* openDATFile (str path) {
+OpenFile* openDATFile (str path, bool search) {
 	logf ("Opening %s...\n", path.chars());
 	
 	// Convert the file name to lowercase since some parts contain uppercase
 	// file names. I'll assume here that the library will always use lowercase
 	// file names for the actual parts..
-	FILE* fp = openLDrawFile (-path, true);
+	FILE* fp;
+	if (search)
+		fp = openLDrawFile (-path, true);
+	else
+		fp = fopen (path, "r");
 	
 	if (!fp) {
 		logf (LOG_Error, "Couldn't open %s: %s\n", path.chars (), strerror (errno));
@@ -274,10 +278,17 @@
 void openMainFile (str zPath) {
 	closeAll ();
 	
-	OpenFile* pFile = openDATFile (zPath);
+	OpenFile* pFile = openDATFile (zPath, false);
 	
-	if (!pFile)
+	if (!pFile) {
+		// Tell the user loading failed.
+		setlocale (LC_ALL, "C");
+		QMessageBox::critical (g_ForgeWindow, "Load Failure",
+			format ("Failed to open %s\nReason: %s", zPath.chars(), strerror (errno)),
+			(QMessageBox::Close), QMessageBox::Close);
+		
 		return;
+	}
 	
 	pFile->implicit = false;
 	g_CurrentFile = pFile;
@@ -542,7 +553,7 @@
 	// Try open the file
 	OpenFile* pFile = findLoadedFile (zFile);
 	if (!pFile)
-		pFile = openDATFile (zFile);
+		pFile = openDATFile (zFile, true);
 	
 	return pFile;
 }
--- a/file.h	Mon Apr 22 16:43:01 2013 +0300
+++ b/file.h	Mon Apr 22 17:01:37 2013 +0300
@@ -75,7 +75,7 @@
 
 // Opens the given file and parses the LDraw code within. Returns a pointer
 // to the opened file or null on error.
-OpenFile* openDATFile (str path);
+OpenFile* openDATFile (str path, bool search);
 
 // Opens the given file and returns a pointer to it, potentially looking in /parts and /p
 FILE* openLDrawFile (str path, bool bSubDirectories);

mercurial