Commit 5b3e912d authored by Rafaël Carré's avatar Rafaël Carré

win32 crash report: simplify crashdump_path usage

no need for dynamic buffers or calculation, it won't change while running
calculate it at start of program and make it const to ensure no threads will modify it
remove one level of indent in check_crashdump()
parent 702e8409
......@@ -43,6 +43,7 @@
# define HeapEnableTerminationOnCorruption (HEAP_INFORMATION_CLASS)1
static void check_crashdump(void);
LONG WINAPI vlc_exception_filter(struct _EXCEPTION_POINTERS *lpExceptionInfo);
static const wchar_t *crashdump_path;
#endif
#ifndef UNDER_CE
......@@ -175,6 +176,13 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
if(crash_handling)
{
static wchar_t path[MAX_PATH];
if( S_OK != SHGetFolderPathW( NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
NULL, SHGFP_TYPE_CURRENT, path ) )
fprintf( stderr, "Can't open the vlc conf PATH\n" );
swprintf( path+wcslen( path ), L"%s", L"\\vlc\\crashdump" );
crashdump_path = &path[0];
check_crashdump();
SetUnhandledExceptionFilter(vlc_exception_filter);
}
......@@ -209,25 +217,13 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
#if !defined( UNDER_CE )
/* Crashdumps handling */
static void get_crashdump_path(wchar_t * wdir)
{
if( S_OK != SHGetFolderPathW( NULL,
CSIDL_APPDATA | CSIDL_FLAG_CREATE,
NULL, SHGFP_TYPE_CURRENT, wdir ) )
fprintf( stderr, "Can't open the vlc conf PATH\n" );
swprintf( wdir+wcslen( wdir ), L"%s", L"\\vlc\\crashdump" );
}
static void check_crashdump()
static void check_crashdump(void)
{
wchar_t * wdir = (wchar_t *)malloc(sizeof(wchar_t)*MAX_PATH);
get_crashdump_path(wdir);
FILE * fd = _wfopen ( wdir, L"r, ccs=UTF-8" );
if( fd )
{
FILE * fd = _wfopen ( crashdump_path, L"r, ccs=UTF-8" );
if( !fd )
return;
fclose( fd );
int answer = MessageBox( NULL, L"VLC media player just crashed." \
" Do you want to send a bug report to the developers team?",
L"VLC crash reporting", MB_YESNO);
......@@ -247,7 +243,7 @@ static void check_crashdump()
swprintf( remote_file, L"/crashes-win32/%04d%02d%02d%02d%02d%02d",
now.wYear, now.wMonth, now.wDay, now.wHour, now.wMinute, now.wSecond );
if( FtpPutFile( ftp, wdir, remote_file, FTP_TRANSFER_TYPE_BINARY, 0) )
if( FtpPutFile( ftp, crashdump_path, remote_file, FTP_TRANSFER_TYPE_BINARY, 0) )
MessageBox( NULL, L"Report sent correctly. Thanks a lot for the help.",
L"Report sent", MB_OK);
else
......@@ -274,9 +270,7 @@ static void check_crashdump()
}
}
_wremove(wdir);
}
free((void *)wdir);
_wremove(crashdump_path);
}
/*****************************************************************************
......@@ -293,10 +287,7 @@ LONG WINAPI vlc_exception_filter(struct _EXCEPTION_POINTERS *lpExceptionInfo)
{
fprintf( stderr, "unhandled vlc exception\n" );
wchar_t * wdir = (wchar_t *)malloc(sizeof(wchar_t)*MAX_PATH);
get_crashdump_path(wdir);
FILE * fd = _wfopen ( wdir, L"w, ccs=UTF-8" );
free((void *)wdir);
FILE * fd = _wfopen ( crashdump_path, L"w, ccs=UTF-8" );
if( !fd )
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment