4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file os2.cpp OS2 related OS support. */
12 #include "../../stdafx.h"
13 #include "../../openttd.h"
14 #include "../../gui.h"
15 #include "../../fileio_func.h"
16 #include "../../fios.h"
17 #include "../../openttd.h"
18 #include "../../core/random_func.hpp"
19 #include "../../string_func.h"
20 #include "../../textbuf_gui.h"
22 #include "table/strings.h"
29 #ifndef __INNOTEK_LIBC__
33 #include "../../safeguards.h"
36 #define INCL_WINCLIPBOARD
39 #ifndef __INNOTEK_LIBC__
43 bool FiosIsRoot(const char *file
)
45 return file
[3] == '\0';
48 void FiosGetDrives(FileList
&file_list
)
50 uint disk
, disk2
, save
, total
;
52 #ifndef __INNOTEK_LIBC__
53 _dos_getdrive(&save
); // save original drive
55 save
= _getdrive(); // save original drive
61 /* get an available drive letter */
62 #ifndef __INNOTEK_LIBC__
63 for (disk
= 1;; disk
++) {
64 _dos_setdrive(disk
, &total
);
66 for (disk
= 'A';; disk
++) {
69 if (disk
>= total
) break;
71 #ifndef __INNOTEK_LIBC__
72 _dos_getdrive(&disk2
);
78 FiosItem
*fios
= file_list
.Append();
79 fios
->type
= FIOS_TYPE_DRIVE
;
81 #ifndef __INNOTEK_LIBC__
82 snprintf(fios
->name
, lengthof(fios
->name
), "%c:", 'A' + disk
- 1);
84 snprintf(fios
->name
, lengthof(fios
->name
), "%c:", disk
);
86 strecpy(fios
->title
, fios
->name
, lastof(fios
->title
));
90 /* Restore the original drive */
91 #ifndef __INNOTEK_LIBC__
92 _dos_setdrive(save
, &total
);
98 bool FiosGetDiskFreeSpace(const char *path
, uint64
*tot
)
100 #ifndef __INNOTEK_LIBC__
101 struct diskfree_t free
;
102 char drive
= path
[0] - 'A' + 1;
104 if (tot
!= NULL
&& _getdiskfree(drive
, &free
) == 0) {
105 *tot
= free
.avail_clusters
* free
.sectors_per_cluster
* free
.bytes_per_sector
;
117 if (statvfs(path
, &s
) != 0) return false;
118 free
= (uint64
)s
.f_frsize
* s
.f_bavail
;
121 if (tot
!= NULL
) *tot
= free
;
126 bool FiosIsValidFile(const char *path
, const struct dirent
*ent
, struct stat
*sb
)
128 char filename
[MAX_PATH
];
130 snprintf(filename
, lengthof(filename
), "%s" PATHSEP
"%s", path
, ent
->d_name
);
131 return stat(filename
, sb
) == 0;
134 bool FiosIsHiddenFile(const struct dirent
*ent
)
136 return ent
->d_name
[0] == '.';
139 void ShowInfo(const char *str
)
146 hmq
= WinCreateMsgQueue((hab
= WinInitialize(0)), 0);
148 /* display the box */
149 rc
= WinMessageBox(HWND_DESKTOP
, HWND_DESKTOP
, (const unsigned char *)str
, (const unsigned char *)"OpenTTD", 0, MB_OK
| MB_MOVEABLE
| MB_INFORMATION
);
151 /* terminate PM env. */
152 WinDestroyMsgQueue(hmq
);
156 void ShowOSErrorBox(const char *buf
, bool system
)
163 hmq
= WinCreateMsgQueue((hab
= WinInitialize(0)), 0);
165 /* display the box */
166 rc
= WinMessageBox(HWND_DESKTOP
, HWND_DESKTOP
, (const unsigned char *)buf
, (const unsigned char *)"OpenTTD", 0, MB_OK
| MB_MOVEABLE
| MB_ERROR
);
168 /* terminate PM env. */
169 WinDestroyMsgQueue(hmq
);
173 int CDECL
main(int argc
, char *argv
[])
175 SetRandomSeed(time(NULL
));
177 /* Make sure our arguments contain only valid UTF-8 characters. */
178 for (int i
= 0; i
< argc
; i
++) ValidateString(argv
[i
]);
180 return openttd_main(argc
, argv
);
183 bool GetClipboardContents(char *buffer
, const char *last
)
185 /* XXX -- Currently no clipboard support implemented with GCC */
186 #ifndef __INNOTEK_LIBC__
189 if (WinOpenClipbrd(hab
))
191 const char *text
= (const char*)WinQueryClipbrdData(hab
, CF_TEXT
);
195 strecpy(buffer
, text
, last
);
196 WinCloseClipbrd(hab
);
200 WinCloseClipbrd(hab
);
207 void CSleep(int milliseconds
)
209 #ifndef __INNOTEK_LIBC__
212 usleep(milliseconds
* 1000);
216 const char *FS2OTTD(const char *name
) {return name
;}
217 const char *OTTD2FS(const char *name
) {return name
;}
219 uint
GetCPUCoreCount()
224 void OSOpenBrowser(const char *url
)
227 DEBUG(misc
, 0, "Failed to open url: %s", url
);