1 /*
2 * parameters_cygwin.cpp - parameters specific for Cygwin build
3 *
4 * Copyright (c) 2001-2010 ARAnyM dev team (see AUTHORS)
5 *
6 * This file is part of the ARAnyM project which builds a new and powerful
7 * TOS/FreeMiNT compatible virtual machine running on almost any hardware.
8 *
9 * ARAnyM is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * ARAnyM is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ARAnyM; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include "sysdeps.h"
25 #include "tools.h"
26 #include "parameters.h"
27 #include "host_filesys.h"
28 #include "win32_supp.h"
29
30 #define DEBUG 0
31 #include "debug.h"
32
33 # include <cstdlib>
34 # include <ShlObj.h>
35
36 #define ARADATA "aranym"
37
get_geometry(const char * dev_path,geo_type geo)38 int get_geometry(const char *dev_path, geo_type geo)
39 {
40 (void)dev_path;
41 (void)geo;
42 return -1;
43 }
44
45 /*
46 * Get the path to a user home folder.
47 */
getHomeFolder(char * buffer,unsigned int bufsize)48 char *HostFilesys::getHomeFolder(char *buffer, unsigned int bufsize)
49 {
50 wchar_t szPath[MAX_PATH];
51 if (SUCCEEDED(::SHGetFolderPathW(NULL,
52 CSIDL_PROFILE,
53 NULL,
54 0,
55 szPath)))
56 {
57 char *path = win32_widechar_to_utf8(szPath);
58 safe_strncpy(buffer, path, bufsize);
59 free(path);
60 strd2upath(buffer, buffer);
61 }
62 else {
63 buffer[0] = '\0'; // last resort - current folder
64 }
65
66 return buffer;
67 }
68
69 /*
70 * Get the path to folder with user-specific files (configuration, NVRAM)
71 */
getConfFolder(char * buffer,unsigned int bufsize)72 char *HostFilesys::getConfFolder(char *buffer, unsigned int bufsize)
73 {
74 HostFilesys::getHomeFolder(buffer, bufsize);
75 return addFilename(buffer, ARANYMHOME, bufsize);
76 }
77
getDataFolder(char * buffer,unsigned int bufsize)78 char *HostFilesys::getDataFolder(char *buffer, unsigned int bufsize)
79 {
80 // data folder is where the program resides
81 static char *real_program_name;
82 if (real_program_name == NULL)
83 {
84 wchar_t name[4096];
85 GetModuleFileNameW(GetModuleHandle(NULL), name, sizeof(name) / sizeof(name[0]));
86 real_program_name = win32_widechar_to_utf8(name);
87 }
88 safe_strncpy(buffer, real_program_name, bufsize);
89 // strip out filename and separator from the path
90 char *ptr = strrchr(buffer, '/'); // first try Unix separator
91 char *ptr2 = strrchr(buffer, '\\'); // then DOS sep.
92 if (ptr2 > ptr)
93 ptr = ptr2;
94 if (ptr != NULL)
95 ptr[0] = '\0';
96 else
97 buffer[0] = '\0'; // last resort - current folder
98
99 return addFilename(buffer, ARADATA, bufsize);
100 }
101
makeDir(char * filename,int perm)102 int HostFilesys::makeDir(char *filename, int perm)
103 {
104 #ifdef OS_mingw
105 (void) perm;
106 return mkdir(filename);
107 #else
108 return mkdir(filename, perm);
109 #endif
110 }
111