~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to mess/src/osd/windows/winutil.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
 
//  winutil.c - Win32 OSD core utility functions
4
 
//
5
 
//============================================================
6
 
//
7
 
//  Copyright Aaron Giles
8
 
//  All rights reserved.
9
 
//
10
 
//  Redistribution and use in source and binary forms, with or
11
 
//  without modification, are permitted provided that the
12
 
//  following conditions are met:
13
 
//
14
 
//    * Redistributions of source code must retain the above
15
 
//      copyright notice, this list of conditions and the
16
 
//      following disclaimer.
17
 
//    * Redistributions in binary form must reproduce the
18
 
//      above copyright notice, this list of conditions and
19
 
//      the following disclaimer in the documentation and/or
20
 
//      other materials provided with the distribution.
21
 
//    * Neither the name 'MAME' nor the names of its
22
 
//      contributors may be used to endorse or promote
23
 
//      products derived from this software without specific
24
 
//      prior written permission.
25
 
//
26
 
//  THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND
27
 
//  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28
 
//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29
 
//  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
30
 
//  EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
31
 
//  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32
 
//  DAMAGE (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33
 
//  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34
 
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
35
 
//  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36
 
//  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
 
//  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
38
 
//  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
 
//
40
 
//============================================================
41
 
 
42
 
// standard windows headers
43
 
#define WIN32_LEAN_AND_MEAN
44
 
#include <windows.h>
45
 
 
46
 
// MAMEOS headers
47
 
#include "winutil.h"
48
 
#include "strconv.h"
49
 
 
50
 
//============================================================
51
 
//  win_error_to_file_error
52
 
//============================================================
53
 
 
54
 
file_error win_error_to_file_error(DWORD error)
55
 
{
56
 
        file_error filerr;
57
 
 
58
 
        // convert a Windows error to a file_error
59
 
        switch (error)
60
 
        {
61
 
                case ERROR_SUCCESS:
62
 
                        filerr = FILERR_NONE;
63
 
                        break;
64
 
 
65
 
                case ERROR_OUTOFMEMORY:
66
 
                        filerr = FILERR_OUT_OF_MEMORY;
67
 
                        break;
68
 
 
69
 
                case ERROR_FILE_NOT_FOUND:
70
 
                case ERROR_PATH_NOT_FOUND:
71
 
                        filerr = FILERR_NOT_FOUND;
72
 
                        break;
73
 
 
74
 
                case ERROR_ACCESS_DENIED:
75
 
                        filerr = FILERR_ACCESS_DENIED;
76
 
                        break;
77
 
 
78
 
                case ERROR_SHARING_VIOLATION:
79
 
                        filerr = FILERR_ALREADY_OPEN;
80
 
                        break;
81
 
 
82
 
                default:
83
 
                        filerr = FILERR_FAILURE;
84
 
                        break;
85
 
        }
86
 
        return filerr;
87
 
}
88
 
 
89
 
 
90
 
 
91
 
//============================================================
92
 
//  win_attributes_to_entry_type
93
 
//============================================================
94
 
 
95
 
osd_dir_entry_type win_attributes_to_entry_type(DWORD attributes)
96
 
{
97
 
        if (attributes == 0xFFFFFFFF)
98
 
                return ENTTYPE_NONE;
99
 
        else if (attributes & FILE_ATTRIBUTE_DIRECTORY)
100
 
                return ENTTYPE_DIR;
101
 
        else
102
 
                return ENTTYPE_FILE;
103
 
}
104
 
 
105
 
 
106
 
 
107
 
//============================================================
108
 
//  win_is_gui_application
109
 
//============================================================
110
 
 
111
 
BOOL win_is_gui_application(void)
112
 
{
113
 
        static BOOL is_gui_frontend;
114
 
        static BOOL is_first_time = TRUE;
115
 
        HMODULE module;
116
 
        BYTE *image_ptr;
117
 
        IMAGE_DOS_HEADER *dos_header;
118
 
        IMAGE_NT_HEADERS *nt_headers;
119
 
        IMAGE_OPTIONAL_HEADER *opt_header;
120
 
 
121
 
        // is this the first time we've been ran?
122
 
        if (is_first_time)
123
 
        {
124
 
                is_first_time = FALSE;
125
 
 
126
 
                // get the current module
127
 
                module = GetModuleHandle(NULL);
128
 
                if (!module)
129
 
                        return FALSE;
130
 
                image_ptr = (BYTE*) module;
131
 
 
132
 
                // access the DOS header
133
 
                dos_header = (IMAGE_DOS_HEADER *) image_ptr;
134
 
                if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
135
 
                        return FALSE;
136
 
 
137
 
                // access the NT headers
138
 
                nt_headers = (IMAGE_NT_HEADERS *) ((BYTE*)(dos_header) + (DWORD)(dos_header->e_lfanew));
139
 
                if (nt_headers->Signature != IMAGE_NT_SIGNATURE)
140
 
                        return FALSE;
141
 
 
142
 
                // access the optional header
143
 
                opt_header = &nt_headers->OptionalHeader;
144
 
                switch (opt_header->Subsystem)
145
 
                {
146
 
                        case IMAGE_SUBSYSTEM_WINDOWS_GUI:
147
 
                                is_gui_frontend = TRUE;
148
 
                                break;
149
 
 
150
 
                        case IMAGE_SUBSYSTEM_WINDOWS_CUI:
151
 
                                is_gui_frontend = FALSE;
152
 
                                break;
153
 
                }
154
 
        }
155
 
        return is_gui_frontend;
156
 
}