Browse Source

Fix a line processing bug under Linux-style systems.
Fix a file detection bug under Windows Phone.

louyihua 8 years ago
parent
commit
5f302cf5dd
5 changed files with 12 additions and 10 deletions
  1. 1 0
      common.h
  2. 4 6
      global.c
  3. 4 3
      text.c
  4. 1 0
      winphone/SDLPal/Package.appxmanifest
  5. 2 1
      winphone/SDLPal/WinPhoneUtil.cpp

+ 1 - 0
common.h

@@ -279,6 +279,7 @@ extern "C"
 # if _MSC_VER < 1900
 #  define vsnprintf _vsnprintf
 # endif
+# define strdup _strdup
 # pragma warning (disable:4244)
 #endif
 

+ 4 - 6
global.c

@@ -206,12 +206,10 @@ PAL_InitGlobals(
 				   }
 				   else if (SDL_strcasecmp(p, "MESSAGEFILENAME") == 0)
 				   {
-					   char *end = ptr + strlen(ptr);
-					   if (end > ptr)
-					   {
-						   if (end[-1] == '\n') end[-1] = 0;
-						   gpGlobals->pszMsgName = strdup(ptr);
-					   }
+					   int n = strlen(ptr);
+					   if (n > 0 && ptr[n - 1] == '\n') ptr[--n] = 0;
+					   if (n > 0 && ptr[n - 1] == '\r') end[--n] = 0;
+					   if (n > 0) gpGlobals->pszMsgName = strdup(ptr);
 				   }
 #if USE_RIX_EXTRA_INIT
 				   else if (SDL_strcasecmp(p, "RIXEXTRAINIT") == 0)

+ 4 - 3
text.c

@@ -153,7 +153,8 @@ PAL_ReadOneLine(
 		}
 		else
 		{
-			if (n > 0 && temp[n - 1] == '\n') temp[n - 1] = 0;
+			if (n > 0 && temp[n - 1] == '\n') temp[--n] = 0;
+			if (n > 0 && temp[n - 1] == '\r') temp[--n] = 0;
 			return temp;
 		}
 	}
@@ -171,14 +172,14 @@ PAL_ReadMessageFile(
 	{
 		struct _msg_entry *next;
 		wchar_t *value;
-	} *cur_val;
+	} *cur_val = NULL;
 	struct _msg_list_entry
 	{
 		struct _msg_list_entry *next;
 		struct _msg_entry *value;
 		int index;
 		int count;
-	} *head = NULL, *item;
+	} *head = NULL, *item = NULL;
 	struct _word_list_entry
 	{
 		struct _word_list_entry *next;

+ 1 - 0
winphone/SDLPal/Package.appxmanifest

@@ -33,6 +33,7 @@
               <FileType>.mp3</FileType>
               <FileType>.ogg</FileType>
               <FileType>.rpg</FileType>
+              <FileType>.bmp</FileType>
             </SupportedFileTypes>
           </FileTypeAssociation>
         </Extension>

+ 2 - 1
winphone/SDLPal/WinPhoneUtil.cpp

@@ -51,7 +51,8 @@ static bool CheckGamePath(Windows::Storage::StorageFolder^ root)
 		for (int i = 0; i < 2; i++)
 		{
 			auto filetask = concurrency::create_task(foldertask.get()->GetFileAsync(optional_required_files[i]));
-			if (WaitOnTask(filetask, 500) && _waccess_s(filetask.get()->Path->Begin(), 2) == 0) return true;
+			try { if (WaitOnTask(filetask, 500) && _waccess_s(filetask.get()->Path->Begin(), 2) == 0) return true; }
+			catch(Platform::Exception^) {}
 		}
 	}
 	catch(Platform::Exception^)