2013-08-09 06:57:18 +02:00
|
|
|
#include "lc_global.h"
|
|
|
|
#include "lc_application.h"
|
2013-08-12 02:26:52 +02:00
|
|
|
#include "lc_qupdatedialog.h"
|
2013-08-16 03:25:51 +02:00
|
|
|
#include "lc_mainwindow.h"
|
2014-05-03 23:16:48 +02:00
|
|
|
#include "view.h"
|
2014-12-08 08:32:39 +01:00
|
|
|
#include "project.h"
|
2015-01-02 02:07:41 +01:00
|
|
|
#include "lc_colors.h"
|
2013-08-09 06:57:18 +02:00
|
|
|
#include <QApplication>
|
|
|
|
|
2013-08-13 06:29:47 +02:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
2013-08-13 06:54:12 +02:00
|
|
|
#include <dbghelp.h>
|
|
|
|
#include <direct.h>
|
|
|
|
#include <shlobj.h>
|
|
|
|
|
|
|
|
#ifdef UNICODE
|
|
|
|
#ifndef _UNICODE
|
|
|
|
#define _UNICODE
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <tchar.h>
|
|
|
|
|
|
|
|
static TCHAR minidumpPath[_MAX_PATH];
|
|
|
|
|
|
|
|
static LONG WINAPI lcSehHandler(PEXCEPTION_POINTERS exceptionPointers)
|
|
|
|
{
|
|
|
|
if (IsDebuggerPresent())
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
|
|
|
|
HMODULE dbgHelp = LoadLibrary(TEXT("dbghelp.dll"));
|
|
|
|
|
|
|
|
if (dbgHelp == NULL)
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
|
|
|
|
HANDLE file = CreateFile(minidumpPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
|
|
|
if (file == INVALID_HANDLE_VALUE)
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
|
|
|
|
typedef BOOL (WINAPI *LPMINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD ProcessId, HANDLE hFile, MINIDUMP_TYPE DumpType, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, CONST PMINIDUMP_USER_STREAM_INFORMATION UserEncoderParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
|
|
|
|
LPMINIDUMPWRITEDUMP miniDumpWriteDump = (LPMINIDUMPWRITEDUMP)GetProcAddress(dbgHelp, "MiniDumpWriteDump");
|
|
|
|
if (!miniDumpWriteDump)
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
|
|
|
|
MINIDUMP_EXCEPTION_INFORMATION mei;
|
|
|
|
|
|
|
|
mei.ThreadId = GetCurrentThreadId();
|
|
|
|
mei.ExceptionPointers = exceptionPointers;
|
|
|
|
mei.ClientPointers = TRUE;
|
|
|
|
|
|
|
|
BOOL writeDump = miniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), file, MiniDumpNormal, exceptionPointers ? &mei : NULL, NULL, NULL);
|
|
|
|
|
|
|
|
CloseHandle(file);
|
|
|
|
FreeLibrary(dbgHelp);
|
|
|
|
|
|
|
|
if (writeDump)
|
|
|
|
{
|
|
|
|
TCHAR message[_MAX_PATH + 256];
|
|
|
|
lstrcpy(message, TEXT("LeoCAD just crashed. Crash information was saved to the file '"));
|
|
|
|
lstrcat(message, minidumpPath);
|
|
|
|
lstrcat(message, TEXT("', please send it to the developers for debugging."));
|
|
|
|
|
|
|
|
MessageBox(NULL, message, TEXT("LeoCAD"), MB_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lcSehInit()
|
|
|
|
{
|
|
|
|
if (SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, minidumpPath) == S_OK)
|
|
|
|
{
|
|
|
|
lstrcat(minidumpPath, TEXT("\\LeoCAD\\"));
|
|
|
|
_tmkdir(minidumpPath);
|
|
|
|
lstrcat(minidumpPath, TEXT("minidump.dmp"));
|
|
|
|
}
|
|
|
|
|
|
|
|
SetUnhandledExceptionFilter(lcSehHandler);
|
|
|
|
}
|
|
|
|
|
2013-08-13 06:29:47 +02:00
|
|
|
static void lcRegisterShellFileTypes()
|
|
|
|
{
|
|
|
|
TCHAR modulePath[_MAX_PATH], longModulePath[_MAX_PATH];
|
|
|
|
TCHAR temp[2*_MAX_PATH];
|
|
|
|
|
|
|
|
GetModuleFileName(NULL, longModulePath, _MAX_PATH);
|
|
|
|
if (GetShortPathName(longModulePath, modulePath, _MAX_PATH) == 0)
|
|
|
|
lstrcpy(modulePath, longModulePath);
|
|
|
|
|
|
|
|
if (RegSetValue(HKEY_CLASSES_ROOT, TEXT("LeoCAD.Project"), REG_SZ, TEXT("LeoCAD Project"), lstrlen(TEXT("LeoCAD Project")) * sizeof(TCHAR)) != ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lstrcpy(temp, modulePath);
|
|
|
|
lstrcat(temp, TEXT(",0"));
|
|
|
|
if (RegSetValue(HKEY_CLASSES_ROOT, TEXT("LeoCAD.Project\\DefaultIcon"), REG_SZ, temp, lstrlen(temp) * sizeof(TCHAR)) != ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lstrcpy(temp, modulePath);
|
|
|
|
lstrcat(temp, TEXT(" \"%1\""));
|
|
|
|
if (RegSetValue(HKEY_CLASSES_ROOT, TEXT("LeoCAD.Project\\shell\\open\\command"), REG_SZ, temp, lstrlen(temp) * sizeof(TCHAR)) != ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LONG size = 2 * _MAX_PATH;
|
|
|
|
LONG result = RegQueryValue(HKEY_CLASSES_ROOT, TEXT(".lcd"), temp, &size);
|
|
|
|
|
|
|
|
if (result != ERROR_SUCCESS || !lstrlen(temp) || lstrcmp(temp, TEXT("LeoCAD.Project")))
|
|
|
|
{
|
|
|
|
if (RegSetValue(HKEY_CLASSES_ROOT, TEXT(".lcd"), REG_SZ, TEXT("LeoCAD.Project"), lstrlen(TEXT("LeoCAD.Project")) * sizeof(TCHAR)) != ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
HKEY key;
|
|
|
|
DWORD disposition = 0;
|
|
|
|
|
|
|
|
if (RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT(".lcd\\ShellNew"), 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &key, &disposition) != ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LONG result = RegSetValueEx(key, TEXT("NullFile"), 0, REG_SZ, (CONST BYTE*)TEXT(""), (lstrlen(TEXT("")) + 1) * sizeof(TCHAR));
|
|
|
|
|
|
|
|
if (RegCloseKey(key) != ERROR_SUCCESS || result != ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
|
|
|
|
QCoreApplication::setOrganizationDomain("leocad.org");
|
2013-08-12 02:26:52 +02:00
|
|
|
QCoreApplication::setOrganizationName("LeoCAD Software");
|
2013-08-09 06:57:18 +02:00
|
|
|
QCoreApplication::setApplicationName("LeoCAD");
|
|
|
|
QCoreApplication::setApplicationVersion(LC_VERSION_TEXT);
|
|
|
|
|
2014-09-16 01:41:46 +02:00
|
|
|
QTranslator Translator;
|
2014-09-18 00:17:42 +02:00
|
|
|
Translator.load(QString("leocad_") + QLocale::system().name().section('_', 0, 0) + ".qm", ":/resources");
|
2014-09-16 01:41:46 +02:00
|
|
|
app.installTranslator(&Translator);
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
g_App = new lcApplication();
|
|
|
|
|
2013-10-21 23:43:03 +02:00
|
|
|
#if defined(Q_OS_WIN)
|
2013-08-09 06:57:18 +02:00
|
|
|
char libPath[LC_MAXPATH], *ptr;
|
|
|
|
strcpy(libPath, argv[0]);
|
|
|
|
ptr = strrchr(libPath,'\\');
|
|
|
|
if (ptr)
|
|
|
|
*(++ptr) = 0;
|
2013-08-13 06:29:47 +02:00
|
|
|
|
|
|
|
lcRegisterShellFileTypes();
|
2013-08-13 06:54:12 +02:00
|
|
|
lcSehInit();
|
2013-10-21 23:43:03 +02:00
|
|
|
#elif defined(Q_OS_MAC)
|
2013-08-09 06:57:18 +02:00
|
|
|
QDir bundlePath = QDir(QCoreApplication::applicationDirPath());
|
|
|
|
bundlePath.cdUp();
|
|
|
|
bundlePath.cdUp();
|
|
|
|
bundlePath = QDir::cleanPath(bundlePath.absolutePath() + "/Contents/Resources/");
|
|
|
|
QByteArray pathArray = bundlePath.absolutePath().toLocal8Bit();
|
|
|
|
const char* libPath = pathArray.data();
|
2013-10-21 23:43:03 +02:00
|
|
|
#else
|
2014-09-13 00:47:08 +02:00
|
|
|
const char* libPath = LC_INSTALL_PREFIX "/share/leocad/";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LC_LDRAW_LIBRARY_PATH
|
|
|
|
const char* LDrawPath = LC_LDRAW_LIBRARY_PATH;
|
|
|
|
#else
|
|
|
|
const char* LDrawPath = NULL;
|
2013-08-09 06:57:18 +02:00
|
|
|
#endif
|
|
|
|
|
2015-07-22 06:00:47 +02:00
|
|
|
if (!g_App->Initialize(argc, argv, libPath, LDrawPath))
|
2013-08-09 06:57:18 +02:00
|
|
|
return 1;
|
|
|
|
|
2015-01-02 02:07:41 +01:00
|
|
|
gMainWindow->SetColorIndex(lcGetColorIndex(4));
|
2013-08-09 06:57:18 +02:00
|
|
|
gMainWindow->UpdateRecentFiles();
|
2015-01-26 00:04:39 +01:00
|
|
|
gMainWindow->show();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2014-09-13 00:17:22 +02:00
|
|
|
#if !LC_DISABLE_UPDATE_CHECK
|
2013-08-12 02:26:52 +02:00
|
|
|
lcDoInitialUpdateCheck();
|
2014-09-13 00:17:22 +02:00
|
|
|
#endif
|
2013-08-12 02:26:52 +02:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
int execReturn = app.exec();
|
|
|
|
|
|
|
|
delete gMainWindow;
|
|
|
|
gMainWindow = NULL;
|
|
|
|
delete g_App;
|
|
|
|
g_App = NULL;
|
|
|
|
|
|
|
|
return execReturn;
|
|
|
|
}
|