Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 11.08 KB | None | 0 0
  1. diff --git a/cross.cpp b/../../../../libretro_dosbox/dosbox-libretro/src/misc/cross.cpp
  2. index bd788480..3e9d4663 100644
  3. --- a/cross.cpp
  4. +++ b/../../../../libretro_dosbox/dosbox-libretro/src/misc/cross.cpp
  5. @@ -1,5 +1,5 @@
  6.  /*
  7. - *  Copyright (C) 2002-2019  The DOSBox Team
  8. + *  Copyright (C) 2002-2013  The DOSBox Team
  9.   *
  10.   *  This program is free software; you can redistribute it and/or modify
  11.   *  it under the terms of the GNU General Public License as published by
  12. @@ -11,49 +11,38 @@
  13.   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.   *  GNU General Public License for more details.
  15.   *
  16. - *  You should have received a copy of the GNU General Public License along
  17. - *  with this program; if not, write to the Free Software Foundation, Inc.,
  18. - *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. + *  You should have received a copy of the GNU General Public License
  20. + *  along with this program; if not, write to the Free Software
  21. + *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. + *
  23. + *  Wengier: LFN support
  24.   */
  25.  
  26. +#include <stdlib.h>
  27. +#include <string>
  28. +
  29. +#include <retro_dirent.h>
  30.  
  31. +#ifdef VITA
  32. +#include <psp2/io/stat.h>
  33. +#endif
  34. +
  35. +#include "../../libretro/libretro.h"
  36.  #include "dosbox.h"
  37.  #include "cross.h"
  38.  #include "support.h"
  39. -#include <string>
  40. -#include <stdlib.h>
  41. -
  42. -#ifdef WIN32
  43. -#ifndef _WIN32_IE
  44. -#define _WIN32_IE 0x0400
  45. -#endif
  46. -#include <shlobj.h>
  47. -#endif
  48.  
  49.  #if defined HAVE_SYS_TYPES_H && defined HAVE_PWD_H
  50.  #include <sys/types.h>
  51.  #include <pwd.h>
  52.  #endif
  53.  
  54. +extern std::string retro_system_directory;
  55.  
  56. -
  57. -#ifdef WIN32
  58. -static void W32_ConfDir(std::string& in,bool create) {
  59. -       int c = create?1:0;
  60. -       char result[MAX_PATH] = { 0 };
  61. -       BOOL r = SHGetSpecialFolderPath(NULL,result,CSIDL_LOCAL_APPDATA,c);
  62. -       if(!r || result[0] == 0) r = SHGetSpecialFolderPath(NULL,result,CSIDL_APPDATA,c);
  63. -       if(!r || result[0] == 0) {
  64. -               char const * windir = getenv("windir");
  65. -               if(!windir) windir = "c:\\windows";
  66. -               safe_strncpy(result,windir,MAX_PATH);
  67. -               char const* appdata = "\\Application Data";
  68. -               size_t len = strlen(result);
  69. -               if(len + strlen(appdata) < MAX_PATH) strcat(result,appdata);
  70. -               if(create) mkdir(result);
  71. -       }
  72. -       in = result;
  73. -}
  74. +#ifdef _WIN32
  75. +const char slash = '\\';
  76. +#else
  77. +const char slash = '/';
  78.  #endif
  79.  
  80.  void Cross::GetPlatformConfigDir(std::string& in) {
  81. @@ -66,7 +55,7 @@ void Cross::GetPlatformConfigDir(std::string& in) {
  82.  #else
  83.         slash = '/';
  84.  #endif
  85. -       in = retro_save_directory;
  86. +       in = retro_save_directory + slash + retro_library_name;
  87.  #elif WIN32
  88.         W32_ConfDir(in,false);
  89.         in += "\\DOSBox";
  90. @@ -81,182 +70,116 @@ void Cross::GetPlatformConfigDir(std::string& in) {
  91.  }
  92.  
  93.  void Cross::GetPlatformConfigName(std::string& in) {
  94. -#ifndef __LIBRETRO__
  95.  #ifdef WIN32
  96.  #define DEFAULT_CONFIG_FILE "dosbox-" VERSION ".conf"
  97.  #elif defined(MACOSX)
  98.  #define DEFAULT_CONFIG_FILE "DOSBox " VERSION " Preferences"
  99.  #else /*linux freebsd*/
  100.  #define DEFAULT_CONFIG_FILE "dosbox-" VERSION ".conf"
  101. -#endif
  102. -#else
  103. -#define DEFAULT_CONFIG_FILE "DOSBox-SVN.conf"
  104.  #endif
  105.         in = DEFAULT_CONFIG_FILE;
  106.  }
  107.  
  108. -void Cross::CreatePlatformConfigDir(std::string& in) {
  109. -#ifdef WIN32
  110. -       W32_ConfDir(in,true);
  111. -       in += "\\DOSBox";
  112. -       mkdir(in.c_str());
  113. -#elif defined(MACOSX)
  114. -       in = "~/Library/Preferences";
  115. -       ResolveHomedir(in);
  116. -       //Don't create it. Assume it exists
  117. -#else
  118. -       in = "~/.dosbox";
  119. -       ResolveHomedir(in);
  120. -       mkdir(in.c_str(),0700);
  121. -#endif
  122. +void Cross::CreatePlatformConfigDir(std::string& in)
  123. +{
  124. +       in += retro_system_directory + slash + "DOSBox";
  125.         in += CROSS_FILESPLIT;
  126.  }
  127.  
  128. -void Cross::ResolveHomedir(std::string & temp_line) {
  129. -       if(!temp_line.size() || temp_line[0] != '~') return; //No ~
  130. -
  131. -       if(temp_line.size() == 1 || temp_line[1] == CROSS_FILESPLIT) { //The ~ and ~/ variant
  132. -               char * home = getenv("HOME");
  133. -               if(home) temp_line.replace(0,1,std::string(home));
  134. -#if defined HAVE_SYS_TYPES_H && defined HAVE_PWD_H && !defined HAVE_LIBNX
  135. -       } else { // The ~username variant
  136. -               std::string::size_type namelen = temp_line.find(CROSS_FILESPLIT);
  137. -               if(namelen == std::string::npos) namelen = temp_line.size();
  138. -               std::string username = temp_line.substr(1,namelen - 1);
  139. -               struct passwd* pass = getpwnam(username.c_str());
  140. -               if(pass) temp_line.replace(0,namelen,pass->pw_dir); //namelen -1 +1(for the ~)
  141. +void Cross::ResolveHomedir(std::string & temp_line)
  142. +{
  143. +   if(!temp_line.size() || temp_line[0] != '~')
  144. +      return; //No ~
  145. +
  146. +   if(temp_line.size() == 1 || temp_line[1] == CROSS_FILESPLIT)
  147. +   {
  148. +      //The ~ and ~/ variant
  149. +      char *home = getenv("HOME");
  150. +      if(home)
  151. +         temp_line.replace(0,1,std::string(home));
  152. +   }
  153. +#if defined HAVE_SYS_TYPES_H && defined HAVE_PWD_H && !defined(__SWITCH__)
  154. +   else
  155. +   {
  156. +      struct passwd *pass;
  157. +      std::string username;
  158. +      // The ~username variant
  159. +      std::string::size_type namelen = temp_line.find(CROSS_FILESPLIT);
  160. +
  161. +      if(namelen == std::string::npos)
  162. +         namelen = temp_line.size();
  163. +      username = temp_line.substr(1,namelen - 1);
  164. +      pass     = getpwnam(username.c_str());
  165. +      if(pass)
  166. +         temp_line.replace(0,namelen,pass->pw_dir); //namelen -1 +1(for the ~)
  167. +   }
  168.  #endif // USERNAME lookup code
  169. -       }
  170.  }
  171.  
  172. -void Cross::CreateDir(std::string const& in) {
  173. +void Cross::CreateDir(std::string const& in)
  174. +{
  175.  #ifdef WIN32
  176. -       mkdir(in.c_str());
  177. +   mkdir(in.c_str());
  178. +#elif defined(VITA)
  179. +   sceIoMkdir(in.c_str(), 0700);
  180.  #else
  181. -       mkdir(in.c_str(),0700);
  182. +   mkdir(in.c_str(),0700);
  183.  #endif
  184.  }
  185.  
  186. -bool Cross::IsPathAbsolute(std::string const& in) {
  187. +bool Cross::IsPathAbsolute(std::string const& in)
  188. +{
  189.         // Absolute paths
  190. -#if defined (WIN32) || defined(OS2)
  191. +#if defined (WIN32)
  192.         // drive letter
  193. -       if (in.size() > 2 && in[1] == ':' ) return true;
  194. +       if (in.size() > 2 && in[1] == ':' )
  195. +      return true;
  196.         // UNC path
  197. -       else if (in.size() > 2 && in[0]=='\\' && in[1]=='\\') return true;
  198. +       else if (in.size() > 2 && in[0]=='\\' && in[1]=='\\')
  199. +      return true;
  200.  #else
  201. -       if (in.size() > 1 && in[0] == '/' ) return true;
  202. +       if (in.size() > 1 && in[0] == '/' )
  203. +      return true;
  204.  #endif
  205.         return false;
  206.  }
  207.  
  208. -#if defined (WIN32)
  209. -
  210. -dir_information* open_directory(const char* dirname) {
  211. -       if (dirname == NULL) return NULL;
  212. -
  213. -       size_t len = strlen(dirname);
  214. -       if (len == 0) return NULL;
  215. -
  216. +dir_information* open_directory(const char* dirname)
  217. +{
  218.         static dir_information dir;
  219.  
  220. -       safe_strncpy(dir.base_path,dirname,MAX_PATH);
  221. -
  222. -       if (dirname[len-1] == '\\') strcat(dir.base_path,"*.*");
  223. -       else                        strcat(dir.base_path,"\\*.*");
  224. -
  225. -       dir.handle = INVALID_HANDLE_VALUE;
  226. -
  227. -       return (access(dirname,0) ? NULL : &dir);
  228. -}
  229. -
  230. -bool read_directory_first(dir_information* dirp, char* entry_name, bool& is_directory) {
  231. -       if (!dirp) return false;
  232. -       dirp->handle = FindFirstFile(dirp->base_path, &dirp->search_data);
  233. -       if (INVALID_HANDLE_VALUE == dirp->handle) {
  234. -               return false;
  235. -       }
  236. -
  237. -       safe_strncpy(entry_name,dirp->search_data.cFileName,(MAX_PATH<CROSS_LEN)?MAX_PATH:CROSS_LEN);
  238. -
  239. -       if (dirp->search_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) is_directory = true;
  240. -       else is_directory = false;
  241. -
  242. -       return true;
  243. -}
  244. -
  245. -bool read_directory_next(dir_information* dirp, char* entry_name, bool& is_directory) {
  246. -       if (!dirp) return false;
  247. -       int result = FindNextFile(dirp->handle, &dirp->search_data);
  248. -       if (result==0) return false;
  249. +       dir.dir = retro_opendir(dirname);
  250.  
  251. -       safe_strncpy(entry_name,dirp->search_data.cFileName,(MAX_PATH<CROSS_LEN)?MAX_PATH:CROSS_LEN);
  252. -
  253. -       if (dirp->search_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) is_directory = true;
  254. -       else is_directory = false;
  255. -
  256. -       return true;
  257. -}
  258. -
  259. -void close_directory(dir_information* dirp) {
  260. -       if (dirp && dirp->handle != INVALID_HANDLE_VALUE) {
  261. -               FindClose(dirp->handle);
  262. -               dirp->handle = INVALID_HANDLE_VALUE;
  263. -       }
  264. -}
  265. -
  266. -#else
  267. -
  268. -dir_information* open_directory(const char* dirname) {
  269. -       static dir_information dir;
  270. -       dir.dir=opendir(dirname);
  271.         safe_strncpy(dir.base_path,dirname,CROSS_LEN);
  272. -       return dir.dir?&dir:NULL;
  273. -}
  274.  
  275. -bool read_directory_first(dir_information* dirp, char* entry_name, bool& is_directory) {
  276. -       if (!dirp) return false;
  277. -       return read_directory_next(dirp,entry_name,is_directory);
  278. +       return dir.dir && dir.dir->directory ? &dir : NULL;
  279.  }
  280.  
  281. -bool read_directory_next(dir_information* dirp, char* entry_name, bool& is_directory) {
  282. -       if (!dirp) return false;
  283. -       struct dirent* dentry = readdir(dirp->dir);
  284. -       if (dentry==NULL) {
  285. -               return false;
  286. -       }
  287. +bool read_directory_next(dir_information* dirp, char* entry_name, char* entry_sname, bool& is_directory)
  288. +{
  289. +   struct stat status;
  290. +   static char buffer[2*CROSS_LEN] = { 0 };
  291.  
  292. -//     safe_strncpy(entry_name,dentry->d_name,(FILENAME_MAX<MAX_PATH)?FILENAME_MAX:MAX_PATH);  // [include stdio.h], maybe pathconf()
  293. -       safe_strncpy(entry_name,dentry->d_name,CROSS_LEN);
  294. +   if (retro_readdir(dirp->dir))
  295. +   {
  296. +      char file_path[4096];
  297.  
  298. -#ifdef DIRENT_HAS_D_TYPE
  299. -       if(dentry->d_type == DT_DIR) {
  300. -               is_directory = true;
  301. -               return true;
  302. -       } else if(dentry->d_type == DT_REG) {
  303. -               is_directory = false;
  304. -               return true;
  305. -       }
  306. -#endif
  307. +      safe_strncpy(entry_name, retro_dirent_get_name(dirp->dir), CROSS_LEN);
  308. +      entry_sname[0]=0;
  309. +      is_directory = retro_dirent_is_dir(dirp->dir, file_path);
  310.  
  311. -       //Maybe only for DT_UNKNOWN if DIRENT_HAD_D_TYPE..
  312. -       static char buffer[2 * CROSS_LEN + 1] = { 0 };
  313. -       static char split[2] = { CROSS_FILESPLIT , 0 };
  314. -       buffer[0] = 0;
  315. -       strcpy(buffer,dirp->base_path);
  316. -       size_t buflen = strlen(buffer);
  317. -       if (buflen && buffer[buflen - 1] != CROSS_FILESPLIT ) strcat(buffer, split);
  318. -       strcat(buffer,entry_name);
  319. -       struct stat status;
  320. +      return true;
  321. +   }
  322.  
  323. -       if (stat(buffer,&status) == 0) is_directory = (S_ISDIR(status.st_mode)>0);
  324. -       else is_directory = false;
  325. -
  326. -       return true;
  327. +   return false;
  328.  }
  329.  
  330. -void close_directory(dir_information* dirp) {
  331. -       if (dirp) closedir(dirp->dir);
  332. +bool read_directory_first(dir_information* dirp, char* entry_name, char* entry_sname, bool& is_directory)
  333. +{
  334. +   return read_directory_next(dirp, entry_name, entry_sname, is_directory);
  335.  }
  336.  
  337. -#endif
  338. +void close_directory(dir_information* dirp)
  339. +{
  340. +       retro_closedir(dirp->dir);
  341. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement