Added missing launcher
[mupen64plus-pandora.git] / source / front-end / src / osal_files_win32.c
CommitLineData
5288f542 1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus-ui-console - osal_files_win32.c *
3 * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4 * Copyright (C) 2009 Richard Goedeken *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
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 *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21
22/* This implements all kinds of system-dependent file handling
23 *
24 */
25
26#include <stdlib.h>
27#include <stdio.h>
28#include <string.h>
29#include <windows.h>
30
31#include "main.h"
32#include "m64p_types.h"
33#include "osal_preproc.h"
34#include "osal_files.h"
35
36/* definitions for system directories to search when looking for mupen64plus plugins */
37const int osal_libsearchdirs = 1;
38const char *osal_libsearchpath[1] = { ".\\" };
39
40osal_lib_search *osal_library_search(const char *searchpath)
41{
42 osal_lib_search *head = NULL, *curr = NULL;
43 WIN32_FIND_DATA entry;
44 HANDLE hDir;
45
46 char *pchSearchPath = (char *) malloc(strlen(searchpath) + 16);
47 if (pchSearchPath == NULL)
48 {
49 DebugMessage(M64MSG_ERROR, "Couldn't allocate memory for file search path in osal_library_search()!");
50 return NULL;
51 }
52 sprintf(pchSearchPath, "%s\\*.dll", searchpath);
53 hDir = FindFirstFile(pchSearchPath, &entry);
54 free(pchSearchPath);
55 if (hDir == INVALID_HANDLE_VALUE)
56 return NULL;
57
58 /* look for any shared libraries in this folder */
59 do
60 {
61 osal_lib_search *newlib = NULL;
62 /* this is a .dll file, so add it to the list */
63 newlib = (osal_lib_search *) malloc(sizeof(osal_lib_search));
64 if (newlib == NULL)
65 {
66 DebugMessage(M64MSG_ERROR, "Memory allocation error in osal_library_search()!");
67 osal_free_lib_list(head);
68 FindClose(hDir);
69 return NULL;
70 }
71 if (head == NULL)
72 {
73 head = curr = newlib;
74 }
75 else
76 {
77 curr->next = newlib;
78 curr = newlib;
79 }
80 /* set up the filepath and filename members */
81 strncpy(curr->filepath, searchpath, PATH_MAX-2);
82 curr->filepath[PATH_MAX-2] = 0;
83 if (curr->filepath[strlen(curr->filepath)-1] != '\\')
84 strcat(curr->filepath, "\\");
85 int pathlen = (int) strlen(curr->filepath);
86 curr->filename = curr->filepath + pathlen;
87 strncat(curr->filepath, entry.cFileName, PATH_MAX - pathlen - 1);
88 curr->filepath[PATH_MAX-1] = 0;
89 /* set plugin_type and next pointer */
90 curr->plugin_type = (m64p_plugin_type) 0;
91 curr->next = NULL;
92 } while (FindNextFile(hDir, &entry));
93
94 FindClose(hDir);
95 return head;
96}
97
98void osal_free_lib_list(osal_lib_search *head)
99{
100 while (head != NULL)
101 {
102 osal_lib_search *next = head->next;
103 free(head);
104 head = next;
105 }
106}