Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
e502fafd
Commit
e502fafd
authored
Sep 22, 2010
by
Damjan Jovanovic
Committed by
Alexandre Julliard
Sep 23, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
winemenubuilder: Isolate the platform-specific icon generation code.
parent
6e46e904
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
58 deletions
+96
-58
winemenubuilder.c
programs/winemenubuilder/winemenubuilder.c
+96
-58
No files found.
programs/winemenubuilder/winemenubuilder.c
View file @
e502fafd
...
@@ -770,85 +770,123 @@ static HRESULT open_icon(LPCWSTR filename, int index, BOOL bWait, IStream **ppSt
...
@@ -770,85 +770,123 @@ static HRESULT open_icon(LPCWSTR filename, int index, BOOL bWait, IStream **ppSt
return
hr
;
return
hr
;
}
}
/* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
static
HRESULT
platform_write_icon
(
IStream
*
icoStream
,
int
exeIndex
,
static
char
*
extract_icon
(
LPCWSTR
path
,
int
index
,
const
char
*
destFilename
,
BOOL
bWait
)
int
bestIndex
,
LPCWSTR
icoPathW
,
const
char
*
destFilename
,
char
**
nativeIdentifier
)
{
{
char
*
icoPathA
=
NULL
;
char
*
iconsDir
=
NULL
;
char
*
pngPath
=
NULL
;
unsigned
short
crc
;
unsigned
short
crc
;
char
*
iconsdir
=
NULL
,
*
ico_path
=
NULL
,
*
ico_name
,
*
png_path
=
NULL
;
char
*
p
,
*
q
;
char
*
s
;
HRESULT
hr
=
S_OK
;
int
n
;
LARGE_INTEGER
zero
;
IStream
*
stream
=
NULL
;
HRESULT
hr
;
/* Where should we save the icon? */
icoPathA
=
wchars_to_utf8_chars
(
icoPathW
);
WINE_TRACE
(
"path=[%s] index=%d
\n
"
,
wine_dbgstr_w
(
path
),
index
);
if
(
icoPathA
==
NULL
)
iconsdir
=
heap_printf
(
"%s/icons"
,
xdg_data_dir
);
if
(
iconsdir
)
{
if
(
mkdir
(
iconsdir
,
0777
)
&&
errno
!=
EEXIST
)
{
{
WINE_WARN
(
"couldn't make icons directory %s
\n
"
,
wine_dbgstr_a
(
iconsdir
))
;
hr
=
E_OUTOFMEMORY
;
goto
end
;
goto
end
;
}
}
crc
=
crc16
(
icoPathA
);
p
=
strrchr
(
icoPathA
,
'\\'
);
if
(
p
==
NULL
)
p
=
icoPathA
;
else
{
*
p
=
0
;
p
++
;
}
}
q
=
strrchr
(
p
,
'.'
);
if
(
q
)
*
q
=
0
;
if
(
destFilename
)
*
nativeIdentifier
=
heap_printf
(
"%s"
,
destFilename
);
else
else
*
nativeIdentifier
=
heap_printf
(
"%04X_%s.%d"
,
crc
,
p
,
exeIndex
);
if
(
*
nativeIdentifier
==
NULL
)
{
{
WINE_TRACE
(
"no icon created
\n
"
)
;
hr
=
E_OUTOFMEMORY
;
return
NULL
;
goto
end
;
}
}
iconsDir
=
heap_printf
(
"%s/icons"
,
xdg_data_dir
);
/* Determine the icon base name */
if
(
iconsDir
==
NULL
)
n
=
WideCharToMultiByte
(
CP_UNIXCP
,
0
,
path
,
-
1
,
NULL
,
0
,
NULL
,
NULL
);
{
ico_path
=
HeapAlloc
(
GetProcessHeap
(),
0
,
n
);
hr
=
E_OUTOFMEMORY
;
WideCharToMultiByte
(
CP_UNIXCP
,
0
,
path
,
-
1
,
ico_path
,
n
,
NULL
,
NULL
);
goto
end
;
s
=
ico_name
=
ico_path
;
while
(
*
s
!=
'\0'
)
{
if
(
*
s
==
'/'
||
*
s
==
'\\'
)
{
*
s
=
'\\'
;
ico_name
=
s
;
}
else
{
*
s
=
tolower
(
*
s
);
}
}
s
++
;
create_directories
(
iconsDir
);
pngPath
=
heap_printf
(
"%s/%s.png"
,
iconsDir
,
*
nativeIdentifier
);
if
(
pngPath
==
NULL
)
{
hr
=
E_OUTOFMEMORY
;
goto
end
;
}
}
if
(
*
ico_name
==
'\\'
)
*
ico_name
++=
'\0'
;
zero
.
QuadPart
=
0
;
s
=
strrchr
(
ico_name
,
'.'
);
hr
=
IStream_Seek
(
icoStream
,
zero
,
STREAM_SEEK_SET
,
NULL
);
if
(
s
)
*
s
=
'\0'
;
if
(
FAILED
(
hr
))
goto
end
;
hr
=
convert_to_native_icon
(
icoStream
,
&
bestIndex
,
1
,
&
CLSID_WICPngEncoder
,
pngPath
,
icoPathW
);
/* Compute the source-path hash */
end:
crc
=
crc16
(
ico_path
);
HeapFree
(
GetProcessHeap
(),
0
,
icoPathA
);
HeapFree
(
GetProcessHeap
(),
0
,
iconsDir
);
HeapFree
(
GetProcessHeap
(),
0
,
pngPath
);
return
hr
;
}
if
(
destFilename
)
/* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
png_path
=
heap_printf
(
"%s/%s.png"
,
iconsdir
,
destFilename
);
static
char
*
extract_icon
(
LPCWSTR
icoPathW
,
int
index
,
const
char
*
destFilename
,
BOOL
bWait
)
else
{
png_path
=
heap_printf
(
"%s/%04x_%s.%d.png"
,
iconsdir
,
crc
,
ico_name
,
index
);
IStream
*
stream
=
NULL
;
if
(
png_path
==
NULL
)
HRESULT
hr
;
{
char
*
nativeIdentifier
=
NULL
;
WINE_ERR
(
"could not extract icon %s, out of memory
\n
"
,
wine_dbgstr_a
(
ico_name
));
ICONDIRENTRY
*
iconDirEntries
=
NULL
;
return
NULL
;
int
numEntries
;
}
int
bestIndex
=
-
1
;
int
maxPixels
=
0
;
int
maxBits
=
0
;
int
i
;
hr
=
open_icon
(
path
,
index
,
bWait
,
&
stream
);
WINE_TRACE
(
"path=[%s] index=%d destFilename=[%s]
\n
"
,
wine_dbgstr_w
(
icoPathW
),
index
,
wine_dbgstr_a
(
destFilename
));
if
(
SUCCEEDED
(
hr
))
hr
=
open_icon
(
icoPathW
,
index
,
bWait
,
&
stream
);
if
(
FAILED
(
hr
))
{
{
hr
=
write_native_icon
(
stream
,
png_path
,
path
);
WINE_WARN
(
"opening icon %s index %d failed, hr=0x%08X
\n
"
,
wine_dbgstr_w
(
icoPathW
),
index
,
hr
);
if
(
SUCCEEDED
(
hr
))
goto
end
;
goto
end
;
else
WINE_ERR
(
"writing native icon for %s index %d failed, hr=0x%08X
\n
"
,
wine_dbgstr_w
(
path
),
index
,
hr
);
}
}
else
hr
=
read_ico_direntries
(
stream
,
&
iconDirEntries
,
&
numEntries
);
WINE_WARN
(
"extracting icon %s index %d failed, hr=0x%08X
\n
"
,
wine_dbgstr_w
(
path
),
index
,
hr
);
if
(
FAILED
(
hr
))
goto
end
;
HeapFree
(
GetProcessHeap
(),
0
,
png_path
);
for
(
i
=
0
;
i
<
numEntries
;
i
++
)
png_path
=
NULL
;
{
WINE_TRACE
(
"[%d]: %d x %d @ %d
\n
"
,
i
,
iconDirEntries
[
i
].
bWidth
,
iconDirEntries
[
i
].
bHeight
,
iconDirEntries
[
i
].
wBitCount
);
if
(
iconDirEntries
[
i
].
wBitCount
>=
maxBits
&&
(
iconDirEntries
[
i
].
bHeight
*
iconDirEntries
[
i
].
bWidth
)
>=
maxPixels
)
{
bestIndex
=
i
;
maxPixels
=
iconDirEntries
[
i
].
bHeight
*
iconDirEntries
[
i
].
bWidth
;
maxBits
=
iconDirEntries
[
i
].
wBitCount
;
}
}
WINE_TRACE
(
"Selected: %d
\n
"
,
bestIndex
);
hr
=
platform_write_icon
(
stream
,
index
,
bestIndex
,
icoPathW
,
destFilename
,
&
nativeIdentifier
);
if
(
FAILED
(
hr
))
WINE_WARN
(
"writing icon failed, error 0x%08X
\n
"
,
hr
);
end:
end:
HeapFree
(
GetProcessHeap
(),
0
,
iconsdir
);
HeapFree
(
GetProcessHeap
(),
0
,
ico_path
);
if
(
stream
)
if
(
stream
)
IStream_Release
(
stream
);
IStream_Release
(
stream
);
return
png_path
;
HeapFree
(
GetProcessHeap
(),
0
,
iconDirEntries
);
if
(
FAILED
(
hr
))
{
HeapFree
(
GetProcessHeap
(),
0
,
nativeIdentifier
);
nativeIdentifier
=
NULL
;
}
return
nativeIdentifier
;
}
}
static
HKEY
open_menus_reg_key
(
void
)
static
HKEY
open_menus_reg_key
(
void
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment