~ubuntu-branches/ubuntu/raring/mame/raring-proposed

« back to all changes in this revision

Viewing changes to mess/src/osd/winui/mui_util.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Jordi Mallach, Emmanuel Kasper
  • Date: 2011-12-19 22:56:27 UTC
  • mfrom: (0.1.2)
  • Revision ID: package-import@ubuntu.com-20111219225627-ub5oga1oys4ogqzm
Tags: 0.144-1
[ Jordi Mallach ]
* Fix syntax errors in DEP5 copyright file (lintian).
* Use a versioned copyright Format specification field.
* Update Vcs-* URLs.
* Move transitional packages to the new metapackages section, and make
  them priority extra.
* Remove references to GNU/Linux and MESS sources from copyright.
* Add build variables for s390x.
* Use .xz tarballs as it cuts 4MB for the upstream sources.
* Add nplayers.ini as a patch. Update copyright file to add CC-BY-SA-3.0.

[ Emmanuel Kasper ]
* New upstream release. Closes: #651538.
* Add Free Desktop compliant png icons of various sizes taken from
  the hydroxygen iconset
* Mess is now built from a new source package, to avoid possible source
  incompatibilities between mame and the mess overlay.
* Mame-tools are not built from the mame source package anymore, but
  from the mess source package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 
3
 
  M.A.M.E.UI  -  Multiple Arcade Machine Emulator with User Interface
4
 
  Win32 Portions Copyright (C) 1997-2003 Michael Soderstrom and Chris Kirmse,
5
 
  Copyright (C) 2003-2007 Chris Kirmse and the MAME32/MAMEUI team.
6
 
 
7
 
  This file is part of MAMEUI, and may only be used, modified and
8
 
  distributed under the terms of the MAME license, in "readme.txt".
9
 
  By continuing to use, modify or distribute this file you indicate
10
 
  that you have read the license and understand and accept it fully.
11
 
 
12
 
 ***************************************************************************/
13
 
 
14
 
/***************************************************************************
15
 
 
16
 
  mui_util.c
17
 
 
18
 
 ***************************************************************************/
19
 
 
20
 
// standard windows headers
21
 
#define WIN32_LEAN_AND_MEAN
22
 
#include <windows.h>
23
 
#include <shellapi.h>
24
 
 
25
 
// standard C headers
26
 
#include <assert.h>
27
 
#include <stdio.h>
28
 
#include <tchar.h>
29
 
 
30
 
#include "emu.h"
31
 
 
32
 
// MAME/MAMEUI headers
33
 
#include "unzip.h"
34
 
#include "sound/samples.h"
35
 
#include "winutf8.h"
36
 
#include "strconv.h"
37
 
#include "winui.h"
38
 
#include "mui_util.h"
39
 
#include "mui_opts.h"
40
 
 
41
 
#include <shlwapi.h>
42
 
 
43
 
/***************************************************************************
44
 
    function prototypes
45
 
 ***************************************************************************/
46
 
 
47
 
/***************************************************************************
48
 
    External variables
49
 
 ***************************************************************************/
50
 
 
51
 
/***************************************************************************
52
 
    Internal structures
53
 
 ***************************************************************************/
54
 
static struct DriversInfo
55
 
{
56
 
        BOOL isClone;
57
 
        BOOL isBroken;
58
 
        BOOL isHarddisk;
59
 
        BOOL hasOptionalBIOS;
60
 
        BOOL isStereo;
61
 
        int screenCount;
62
 
        BOOL isVector;
63
 
        BOOL usesRoms;
64
 
        BOOL usesSamples;
65
 
        BOOL usesTrackball;
66
 
        BOOL usesLightGun;
67
 
        BOOL usesMouse;
68
 
        BOOL supportsSaveState;
69
 
        BOOL isVertical;
70
 
} *drivers_info = NULL;
71
 
 
72
 
 
73
 
/***************************************************************************
74
 
    External functions
75
 
 ***************************************************************************/
76
 
 
77
 
/*
78
 
    ErrorMsg
79
 
*/
80
 
void __cdecl ErrorMsg(const char* fmt, ...)
81
 
{
82
 
        static FILE*    pFile = NULL;
83
 
        DWORD                   dwWritten;
84
 
        char                    buf[5000];
85
 
        char                    buf2[5000];
86
 
        va_list                 va;
87
 
 
88
 
        va_start(va, fmt);
89
 
 
90
 
        vsprintf(buf, fmt, va);
91
 
 
92
 
        win_message_box_utf8(GetActiveWindow(), buf, MAMEUINAME, MB_OK | MB_ICONERROR);
93
 
 
94
 
        strcpy(buf2, MAMEUINAME ": ");
95
 
        strcat(buf2,buf);
96
 
        strcat(buf2, "\n");
97
 
 
98
 
        WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buf2, strlen(buf2), &dwWritten, NULL);
99
 
 
100
 
        if (pFile == NULL)
101
 
                pFile = fopen("debug.txt", "wt");
102
 
 
103
 
        if (pFile != NULL)
104
 
        {
105
 
                fprintf(pFile, "%s", buf2);
106
 
                fflush(pFile);
107
 
        }
108
 
 
109
 
        va_end(va);
110
 
}
111
 
 
112
 
void __cdecl dprintf(const char* fmt, ...)
113
 
{
114
 
        char    buf[5000];
115
 
        va_list va;
116
 
 
117
 
        va_start(va, fmt);
118
 
 
119
 
        _vsnprintf(buf,sizeof(buf),fmt,va);
120
 
 
121
 
        win_output_debug_string_utf8(buf);
122
 
 
123
 
        va_end(va);
124
 
}
125
 
 
126
 
UINT GetDepth(HWND hWnd)
127
 
{
128
 
        UINT    nBPP;
129
 
        HDC     hDC;
130
 
 
131
 
        hDC = GetDC(hWnd);
132
 
 
133
 
        nBPP = GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps(hDC, PLANES);
134
 
 
135
 
        ReleaseDC(hWnd, hDC);
136
 
 
137
 
        return nBPP;
138
 
}
139
 
 
140
 
/*
141
 
 * Return TRUE if comctl32.dll is version 4.71 or greater
142
 
 * otherwise return FALSE.
143
 
 */
144
 
LONG GetCommonControlVersion()
145
 
{
146
 
        HMODULE hModule = GetModuleHandle(TEXT("comctl32"));
147
 
 
148
 
        if (hModule)
149
 
        {
150
 
                FARPROC lpfnICCE = GetProcAddress(hModule, "InitCommonControlsEx");
151
 
 
152
 
                if (NULL != lpfnICCE)
153
 
                {
154
 
                        FARPROC lpfnDLLI = GetProcAddress(hModule, "DllInstall");
155
 
 
156
 
                        if (NULL != lpfnDLLI)
157
 
                        {
158
 
                                /* comctl 4.71 or greater */
159
 
 
160
 
                                // see if we can find out exactly
161
 
 
162
 
                                DLLGETVERSIONPROC pDllGetVersion;
163
 
                                pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hModule, "DllGetVersion");
164
 
 
165
 
                                /* Because some DLLs might not implement this function, you
166
 
                   must test for it explicitly. Depending on the particular
167
 
                   DLL, the lack of a DllGetVersion function can be a useful
168
 
                   indicator of the version. */
169
 
 
170
 
                                if(pDllGetVersion)
171
 
                                {
172
 
                                        DLLVERSIONINFO dvi;
173
 
                                        HRESULT hr;
174
 
 
175
 
                                        ZeroMemory(&dvi, sizeof(dvi));
176
 
                                        dvi.cbSize = sizeof(dvi);
177
 
 
178
 
                                        hr = (*pDllGetVersion)(&dvi);
179
 
 
180
 
                                        if (SUCCEEDED(hr))
181
 
                                        {
182
 
                                                return PACKVERSION(dvi.dwMajorVersion, dvi.dwMinorVersion);
183
 
                                        }
184
 
                                }
185
 
                                return PACKVERSION(4,71);
186
 
                        }
187
 
                        return PACKVERSION(4,7);
188
 
                }
189
 
                return PACKVERSION(4,0);
190
 
        }
191
 
        /* DLL not found */
192
 
        return PACKVERSION(0,0);
193
 
}
194
 
 
195
 
void DisplayTextFile(HWND hWnd, const char *cName)
196
 
{
197
 
        HINSTANCE hErr;
198
 
        LPCTSTR   msg = 0;
199
 
        LPTSTR    tName;
200
 
 
201
 
        tName = tstring_from_utf8(cName);
202
 
        if( !tName )
203
 
                return;
204
 
 
205
 
        hErr = ShellExecute(hWnd, NULL, tName, NULL, NULL, SW_SHOWNORMAL);
206
 
        if ((FPTR)hErr > 32)
207
 
        {
208
 
                osd_free(tName);
209
 
                return;
210
 
        }
211
 
 
212
 
        switch((FPTR)hErr)
213
 
        {
214
 
        case 0:
215
 
                msg = TEXT("The operating system is out of memory or resources.");
216
 
                break;
217
 
 
218
 
        case ERROR_FILE_NOT_FOUND:
219
 
                msg = TEXT("The specified file was not found.");
220
 
                break;
221
 
 
222
 
        case SE_ERR_NOASSOC :
223
 
                msg = TEXT("There is no application associated with the given filename extension.");
224
 
                break;
225
 
 
226
 
        case SE_ERR_OOM :
227
 
                msg = TEXT("There was not enough memory to complete the operation.");
228
 
                break;
229
 
 
230
 
        case SE_ERR_PNF :
231
 
                msg = TEXT("The specified path was not found.");
232
 
                break;
233
 
 
234
 
        case SE_ERR_SHARE :
235
 
                msg = TEXT("A sharing violation occurred.");
236
 
                break;
237
 
 
238
 
        default:
239
 
                msg = TEXT("Unknown error.");
240
 
        }
241
 
 
242
 
        MessageBox(NULL, msg, tName, MB_OK);
243
 
 
244
 
        osd_free(tName);
245
 
}
246
 
 
247
 
char* MyStrStrI(const char* pFirst, const char* pSrch)
248
 
{
249
 
        char* cp = (char*)pFirst;
250
 
        char* s1;
251
 
        char* s2;
252
 
 
253
 
        while (*cp)
254
 
        {
255
 
                s1 = cp;
256
 
                s2 = (char*)pSrch;
257
 
 
258
 
                while (*s1 && *s2 && !mame_strnicmp(s1, s2, 1))
259
 
                        s1++, s2++;
260
 
 
261
 
                if (!*s2)
262
 
                        return cp;
263
 
 
264
 
                cp++;
265
 
        }
266
 
        return NULL;
267
 
}
268
 
 
269
 
char * ConvertToWindowsNewlines(const char *source)
270
 
{
271
 
        static char buf[1024 * 1024];
272
 
        char *dest;
273
 
 
274
 
        dest = buf;
275
 
        while (*source != 0)
276
 
        {
277
 
                if (*source == '\n')
278
 
                {
279
 
                        *dest++ = '\r';
280
 
                        *dest++ = '\n';
281
 
                }
282
 
                else
283
 
                        *dest++ = *source;
284
 
                source++;
285
 
        }
286
 
        *dest = 0;
287
 
        return buf;
288
 
}
289
 
 
290
 
/* Lop off path and extention from a source file name
291
 
 * This assumes their is a pathname passed to the function
292
 
 * like src\drivers\blah.c
293
 
 */
294
 
const char * GetDriverFilename(int nIndex)
295
 
{
296
 
        static char tmp[40];
297
 
        const char *ptmp;
298
 
 
299
 
        const char *s = driver_list::driver(nIndex).source_file;
300
 
 
301
 
        tmp[0] = '\0';
302
 
 
303
 
        ptmp = strrchr(s, '\\');
304
 
        if (ptmp == NULL) {
305
 
                ptmp = strrchr(s, '/');
306
 
        }
307
 
        else {
308
 
                const char *ptmp2;
309
 
                ptmp2 = strrchr(ptmp, '/');
310
 
                if (ptmp2 != NULL) {
311
 
                        ptmp = ptmp2;
312
 
                }
313
 
        }
314
 
        if (ptmp == NULL)
315
 
                return s;
316
 
 
317
 
        ptmp++;
318
 
        strcpy(tmp,ptmp);
319
 
        return tmp;
320
 
}
321
 
 
322
 
BOOL isDriverVector(const machine_config *config)
323
 
{
324
 
        const screen_device *screen  = config->first_screen();
325
 
 
326
 
        if (screen != NULL) {
327
 
                // parse "vector.ini" for vector games
328
 
                if (SCREEN_TYPE_VECTOR == screen->screen_type())
329
 
                {
330
 
                        return TRUE;
331
 
                }
332
 
        }
333
 
        return FALSE;
334
 
}
335
 
 
336
 
int numberOfScreens(const machine_config *config)
337
 
{
338
 
        const screen_device *screen  = config->first_screen();
339
 
        int i=0;
340
 
        for (; screen != NULL; screen = screen->next_screen()) {
341
 
                i++;
342
 
        }
343
 
        return i;
344
 
}
345
 
 
346
 
 
347
 
 
348
 
int numberOfSpeakers(const machine_config *config)
349
 
{
350
 
        return config->devicelist().count(SPEAKER);
351
 
}
352
 
 
353
 
static struct DriversInfo* GetDriversInfo(int driver_index)
354
 
{
355
 
        if (drivers_info == NULL)
356
 
        {
357
 
                int ndriver;
358
 
                drivers_info = (DriversInfo*)malloc(sizeof(struct DriversInfo) * driver_list::total());
359
 
                for (ndriver = 0; ndriver < driver_list::total(); ndriver++)
360
 
                {
361
 
                        const game_driver *gamedrv = &driver_list::driver(ndriver);
362
 
                        struct DriversInfo *gameinfo = &drivers_info[ndriver];
363
 
                        const rom_entry *region, *rom;
364
 
                        machine_config config(*gamedrv, MameUIGlobal());
365
 
                        const rom_source *source;
366
 
                        int num_speakers;
367
 
 
368
 
                        gameinfo->isClone = (GetParentRomSetIndex(gamedrv) != -1);
369
 
                        gameinfo->isBroken = ((gamedrv->flags & GAME_NOT_WORKING) != 0);
370
 
                        gameinfo->supportsSaveState = ((gamedrv->flags & GAME_SUPPORTS_SAVE) != 0);
371
 
                        gameinfo->isHarddisk = FALSE;
372
 
                        gameinfo->isVertical = (gamedrv->flags & ORIENTATION_SWAP_XY) ? TRUE : FALSE;
373
 
                        for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source))
374
 
                        {
375
 
                                for (region = rom_first_region(*source); region; region = rom_next_region(region))
376
 
                                {
377
 
                                        if (ROMREGION_ISDISKDATA(region))
378
 
                                                gameinfo->isHarddisk = TRUE;
379
 
                                }
380
 
                        }
381
 
                        gameinfo->hasOptionalBIOS = FALSE;
382
 
                        if (gamedrv->rom != NULL)
383
 
                        {
384
 
                                for (rom = gamedrv->rom; !ROMENTRY_ISEND(rom); rom++)
385
 
                                {
386
 
                                        if (ROMENTRY_ISSYSTEM_BIOS(rom))
387
 
                                        {
388
 
                                                gameinfo->hasOptionalBIOS = TRUE;
389
 
                                                break;
390
 
                                        }
391
 
                                }
392
 
                        }
393
 
 
394
 
                        num_speakers = numberOfSpeakers(&config);
395
 
 
396
 
                        gameinfo->isStereo = (num_speakers > 1);
397
 
                        gameinfo->screenCount = numberOfScreens(&config);
398
 
                        gameinfo->isVector = isDriverVector(&config); // ((drv.video_attributes & VIDEO_TYPE_VECTOR) != 0);
399
 
                        gameinfo->usesRoms = FALSE;
400
 
                        for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source))
401
 
                        {
402
 
                                for (region = rom_first_region(*source); region; region = rom_next_region(region))
403
 
                                {
404
 
                                        for (rom = rom_first_file(region); rom; rom = rom_next_file(rom))
405
 
                                        {
406
 
                                                gameinfo->usesRoms = TRUE;
407
 
                                                break;
408
 
                                        }
409
 
                                }
410
 
                        }
411
 
                        gameinfo->usesSamples = FALSE;
412
 
 
413
 
                        {
414
 
                                const device_sound_interface *sound = NULL;
415
 
                                const char * const * samplenames = NULL;
416
 
                                for (bool gotone = config.devicelist().first(sound); gotone; gotone = sound->next(sound)) {
417
 
                                        if (sound->device().type() == SAMPLES)
418
 
                                        {
419
 
                                                const samples_interface *intf = (const samples_interface *)sound->device().static_config();
420
 
                                                samplenames = intf->samplenames;
421
 
 
422
 
                                                if (samplenames != 0 && samplenames[0] != 0)
423
 
                                                {
424
 
                                                        gameinfo->usesSamples = TRUE;
425
 
                                                        break;
426
 
                                                }
427
 
                                        }
428
 
                                }
429
 
                        }
430
 
 
431
 
                        gameinfo->usesTrackball = FALSE;
432
 
                        gameinfo->usesLightGun = FALSE;
433
 
                        if (gamedrv->ipt != NULL)
434
 
                        {
435
 
                                input_port_config *port;
436
 
                                ioport_list portlist;
437
 
                                astring errors;
438
 
                                for (device_t *cfg = config.devicelist().first(); cfg != NULL; cfg = cfg->next())
439
 
                                {
440
 
                                        if (cfg->input_ports()!=NULL) {
441
 
                                                input_port_list_init(*cfg, portlist, errors);
442
 
                                        }
443
 
                                }
444
 
 
445
 
                                for (port = portlist.first(); port != NULL; port = port->next())
446
 
                                {
447
 
                                        input_field_config *field;
448
 
                                        for (field = port->fieldlist().first(); field != NULL; field = field->next())
449
 
                                        {
450
 
                                                UINT32 type;
451
 
                                                type = field->type;
452
 
                                                if (type == IPT_END)
453
 
                                                        break;
454
 
                                                if (type == IPT_DIAL || type == IPT_PADDLE ||
455
 
                                                        type == IPT_TRACKBALL_X || type == IPT_TRACKBALL_Y ||
456
 
                                                        type == IPT_AD_STICK_X || type == IPT_AD_STICK_Y)
457
 
                                                        gameinfo->usesTrackball = TRUE;
458
 
                                                if (type == IPT_LIGHTGUN_X || type == IPT_LIGHTGUN_Y)
459
 
                                                        gameinfo->usesLightGun = TRUE;
460
 
                                                if (type == IPT_MOUSE_X || type == IPT_MOUSE_Y)
461
 
                                                        gameinfo->usesMouse = TRUE;
462
 
                                        }
463
 
                                }
464
 
                        }
465
 
                }
466
 
        }
467
 
        return &drivers_info[driver_index];
468
 
}
469
 
 
470
 
BOOL DriverIsClone(int driver_index)
471
 
{
472
 
         return GetDriversInfo(driver_index)->isClone;
473
 
}
474
 
 
475
 
BOOL DriverIsBroken(int driver_index)
476
 
{
477
 
        return GetDriversInfo(driver_index)->isBroken;
478
 
}
479
 
 
480
 
BOOL DriverIsHarddisk(int driver_index)
481
 
{
482
 
        return GetDriversInfo(driver_index)->isHarddisk;
483
 
}
484
 
 
485
 
BOOL DriverIsBios(int driver_index)
486
 
{
487
 
        BOOL bBios = FALSE;
488
 
        if( !( (driver_list::driver(driver_index).flags & GAME_IS_BIOS_ROOT ) == 0)   )
489
 
                bBios = TRUE;
490
 
        return bBios;
491
 
}
492
 
 
493
 
BOOL DriverIsMechanical(int driver_index)
494
 
{
495
 
        BOOL bMechanical = FALSE;
496
 
        if( !( (driver_list::driver(driver_index).flags & GAME_MECHANICAL ) == 0)   )
497
 
                bMechanical = TRUE;
498
 
        return bMechanical;
499
 
}
500
 
 
501
 
BOOL DriverHasOptionalBIOS(int driver_index)
502
 
{
503
 
        return GetDriversInfo(driver_index)->hasOptionalBIOS;
504
 
}
505
 
 
506
 
BOOL DriverIsStereo(int driver_index)
507
 
{
508
 
        return GetDriversInfo(driver_index)->isStereo;
509
 
}
510
 
 
511
 
int DriverNumScreens(int driver_index)
512
 
{
513
 
        return GetDriversInfo(driver_index)->screenCount;
514
 
}
515
 
 
516
 
BOOL DriverIsVector(int driver_index)
517
 
{
518
 
        return GetDriversInfo(driver_index)->isVector;
519
 
}
520
 
 
521
 
BOOL DriverUsesRoms(int driver_index)
522
 
{
523
 
        return GetDriversInfo(driver_index)->usesRoms;
524
 
}
525
 
 
526
 
BOOL DriverUsesSamples(int driver_index)
527
 
{
528
 
        return GetDriversInfo(driver_index)->usesSamples;
529
 
}
530
 
 
531
 
BOOL DriverUsesTrackball(int driver_index)
532
 
{
533
 
        return GetDriversInfo(driver_index)->usesTrackball;
534
 
}
535
 
 
536
 
BOOL DriverUsesLightGun(int driver_index)
537
 
{
538
 
        return GetDriversInfo(driver_index)->usesLightGun;
539
 
}
540
 
 
541
 
BOOL DriverUsesMouse(int driver_index)
542
 
{
543
 
        return GetDriversInfo(driver_index)->usesMouse;
544
 
}
545
 
 
546
 
BOOL DriverSupportsSaveState(int driver_index)
547
 
{
548
 
        return GetDriversInfo(driver_index)->supportsSaveState;
549
 
}
550
 
 
551
 
BOOL DriverIsVertical(int driver_index) {
552
 
        return GetDriversInfo(driver_index)->isVertical;
553
 
}
554
 
 
555
 
void FlushFileCaches(void)
556
 
{
557
 
        zip_file_cache_clear();
558
 
}
559
 
 
560
 
BOOL StringIsSuffixedBy(const char *s, const char *suffix)
561
 
{
562
 
        return (strlen(s) > strlen(suffix)) && (strcmp(s + strlen(s) - strlen(suffix), suffix) == 0);
563
 
}
564
 
 
565
 
/***************************************************************************
566
 
    Win32 wrappers
567
 
 ***************************************************************************/
568
 
 
569
 
BOOL SafeIsAppThemed(void)
570
 
{
571
 
        BOOL bResult = FALSE;
572
 
        HMODULE hThemes;
573
 
        BOOL (WINAPI *pfnIsAppThemed)(void);
574
 
 
575
 
        hThemes = LoadLibrary(TEXT("uxtheme.dll"));
576
 
        if (hThemes != NULL)
577
 
        {
578
 
                pfnIsAppThemed = (BOOL (WINAPI *)(void)) GetProcAddress(hThemes, "IsAppThemed");
579
 
                if (pfnIsAppThemed != NULL)
580
 
                        bResult = pfnIsAppThemed();
581
 
                FreeLibrary(hThemes);
582
 
        }
583
 
        return bResult;
584
 
 
585
 
}
586
 
 
587
 
 
588
 
void GetSystemErrorMessage(DWORD dwErrorId, TCHAR **tErrorMessage)
589
 
{
590
 
        if( FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwErrorId, 0, (LPTSTR)tErrorMessage, 0, NULL) == 0 )
591
 
        {
592
 
                *tErrorMessage = (LPTSTR)LocalAlloc(LPTR, MAX_PATH * sizeof(TCHAR));
593
 
                _tcscpy(*tErrorMessage, TEXT("Unknown Error"));
594
 
        }
595
 
}
596
 
 
597
 
 
598
 
//============================================================
599
 
//  win_extract_icon_utf8
600
 
//============================================================
601
 
 
602
 
HICON win_extract_icon_utf8(HINSTANCE inst, const char* exefilename, UINT iconindex)
603
 
{
604
 
        HICON icon = 0;
605
 
        TCHAR* t_exefilename = tstring_from_utf8(exefilename);
606
 
        if( !t_exefilename )
607
 
                return icon;
608
 
 
609
 
        icon = ExtractIcon(inst, t_exefilename, iconindex);
610
 
 
611
 
        osd_free(t_exefilename);
612
 
 
613
 
        return icon;
614
 
}
615
 
 
616
 
 
617
 
 
618
 
//============================================================
619
 
//  win_tstring_strdup
620
 
//============================================================
621
 
 
622
 
TCHAR* win_tstring_strdup(LPCTSTR str)
623
 
{
624
 
        TCHAR *cpy = NULL;
625
 
        if (str != NULL)
626
 
        {
627
 
                cpy = (TCHAR*)osd_malloc((_tcslen(str) + 1) * sizeof(TCHAR));
628
 
                if (cpy != NULL)
629
 
                        _tcscpy(cpy, str);
630
 
        }
631
 
        return cpy;
632
 
}
633
 
 
634
 
//============================================================
635
 
//  win_create_file_utf8
636
 
//============================================================
637
 
 
638
 
HANDLE win_create_file_utf8(const char* filename, DWORD desiredmode, DWORD sharemode,
639
 
                                                        LPSECURITY_ATTRIBUTES securityattributes, DWORD creationdisposition,
640
 
                                                        DWORD flagsandattributes, HANDLE templatehandle)
641
 
{
642
 
        HANDLE result = 0;
643
 
        TCHAR* t_filename = tstring_from_utf8(filename);
644
 
        if( !t_filename )
645
 
                return result;
646
 
 
647
 
        result = CreateFile(t_filename, desiredmode, sharemode, securityattributes, creationdisposition,
648
 
                                                flagsandattributes, templatehandle);
649
 
 
650
 
        osd_free(t_filename);
651
 
 
652
 
        return result;
653
 
}
654
 
 
655
 
//============================================================
656
 
//  win_get_current_directory_utf8
657
 
//============================================================
658
 
 
659
 
DWORD win_get_current_directory_utf8(DWORD bufferlength, char* buffer)
660
 
{
661
 
        DWORD result = 0;
662
 
        TCHAR* t_buffer = NULL;
663
 
        char* utf8_buffer = NULL;
664
 
 
665
 
        if( bufferlength > 0 ) {
666
 
                t_buffer = (TCHAR*)malloc((bufferlength * sizeof(TCHAR)) + 1);
667
 
                if( !t_buffer )
668
 
                        return result;
669
 
        }
670
 
 
671
 
        result = GetCurrentDirectory(bufferlength, t_buffer);
672
 
 
673
 
        if( bufferlength > 0 ) {
674
 
                utf8_buffer = utf8_from_tstring(t_buffer);
675
 
                if( !utf8_buffer ) {
676
 
                        osd_free(t_buffer);
677
 
                        return result;
678
 
                }
679
 
        }
680
 
 
681
 
        strncpy(buffer, utf8_buffer, bufferlength);
682
 
 
683
 
        if( utf8_buffer )
684
 
                osd_free(utf8_buffer);
685
 
 
686
 
        if( t_buffer )
687
 
                free(t_buffer);
688
 
 
689
 
        return result;
690
 
}
691
 
 
692
 
//============================================================
693
 
//  win_find_first_file_utf8
694
 
//============================================================
695
 
 
696
 
HANDLE win_find_first_file_utf8(const char* filename, LPWIN32_FIND_DATA findfiledata)
697
 
{
698
 
        HANDLE result = 0;
699
 
        TCHAR* t_filename = tstring_from_utf8(filename);
700
 
        if( !t_filename )
701
 
                return result;
702
 
 
703
 
        result = FindFirstFile(t_filename, findfiledata);
704
 
 
705
 
        osd_free(t_filename);
706
 
 
707
 
        return result;
708
 
}
709