OSDN Git Service

Extinguished some remaining uses of argv[] or QApplication::arguments().
authorlordmulder <mulder2@gmx.de>
Sat, 23 Jun 2012 16:18:57 +0000 (18:18 +0200)
committerlordmulder <mulder2@gmx.de>
Sat, 23 Jun 2012 16:18:57 +0000 (18:18 +0200)
LameXP_VS2010.vcxproj
etc/Translation/Blank.ts
etc/Translation/LameXP_PL.ts
etc/Translation/LameXP_SV.ts
src/Config.h
src/Dialog_Processing.cpp
src/Global.cpp
src/Global.h
src/Main.cpp

index 2d3e00f..064ac66 100644 (file)
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <SubSystem>Windows</SubSystem>
       <TargetMachine>MachineX86</TargetMachine>
+      <EntryPointSymbol>lamexp_entry_point</EntryPointSymbol>
     </Link>
     <PostBuildEvent>
       <Message>Copy plugin DLL%27s</Message>
@@ -168,6 +169,7 @@ copy /Y "$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\bin\Win32\*.manifes
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <SubSystem>Windows</SubSystem>
       <TargetMachine>MachineX86</TargetMachine>
+      <EntryPointSymbol>lamexp_entry_point</EntryPointSymbol>
     </Link>
     <PostBuildEvent>
       <Message>Copy plugin DLL%27s</Message>
@@ -236,7 +238,7 @@ copy /Y "$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\bin\Win32\*.manifes
       <SetChecksum>true</SetChecksum>
       <TargetMachine>MachineX86</TargetMachine>
       <MinimumRequiredVersion>5.0</MinimumRequiredVersion>
-      <EntryPointSymbol>lamexp_crt_startup</EntryPointSymbol>
+      <EntryPointSymbol>lamexp_entry_point</EntryPointSymbol>
       <MapFileName>
       </MapFileName>
       <TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
@@ -306,7 +308,7 @@ del "$(TargetDir)imageformats\q???d4.dll"
       <SetChecksum>true</SetChecksum>
       <TargetMachine>MachineX86</TargetMachine>
       <MinimumRequiredVersion>5.0</MinimumRequiredVersion>
-      <EntryPointSymbol>lamexp_crt_startup</EntryPointSymbol>
+      <EntryPointSymbol>lamexp_entry_point</EntryPointSymbol>
       <GenerateMapFile>false</GenerateMapFile>
       <MapFileName>
       </MapFileName>
@@ -371,7 +373,7 @@ del "$(TargetDir)imageformats\q???d4.dll"
       <SetChecksum>true</SetChecksum>
       <TargetMachine>MachineX86</TargetMachine>
       <MinimumRequiredVersion>5.0</MinimumRequiredVersion>
-      <EntryPointSymbol>lamexp_crt_startup</EntryPointSymbol>
+      <EntryPointSymbol>lamexp_entry_point</EntryPointSymbol>
       <GenerateMapFile>false</GenerateMapFile>
       <MapFileName>
       </MapFileName>
index ea73f97..5d9c28a 100644 (file)
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../../src/Global.cpp" line="1059"/>
+        <location filename="../../src/Global.cpp" line="1071"/>
         <source>Executable &apos;%1&apos; requires Qt v%2, but found Qt v%3.</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../../src/Global.cpp" line="1064"/>
+        <location filename="../../src/Global.cpp" line="1076"/>
         <source>Executable &apos;%1&apos; was built for Qt &apos;%2&apos;, but found Qt &apos;%3&apos;.</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../../src/Global.cpp" line="1077"/>
+        <location filename="../../src/Global.cpp" line="1089"/>
         <source>Executable &apos;%1&apos; requires Windows 2000 or later.</source>
         <translation type="unfinished"></translation>
     </message>
index 1276beb..9237741 100644 (file)
         <translation type="unfinished">Plik wykonywalny &apos;%1&apos; nie działa w trybie kompatybilności z Windows.</translation>
     </message>
     <message>
-        <location filename="../../src/Global.cpp" line="1059"/>
+        <location filename="../../src/Global.cpp" line="1071"/>
         <source>Executable &apos;%1&apos; requires Qt v%2, but found Qt v%3.</source>
         <translation type="unfinished">Plik wykonywalny &apos;%1&apos; wymaga Qt v%2, znaleziono jednak Qt v%3.</translation>
     </message>
     <message>
-        <location filename="../../src/Global.cpp" line="1064"/>
+        <location filename="../../src/Global.cpp" line="1076"/>
         <source>Executable &apos;%1&apos; was built for Qt &apos;%2&apos;, but found Qt &apos;%3&apos;.</source>
         <translation type="unfinished">Plik wykonywalny &quot;%1&quot; został skompilowany dla Qt &quot;%2&quot;, znaleziono &quot;%3&quot;.</translation>
     </message>
     <message>
-        <location filename="../../src/Global.cpp" line="1077"/>
+        <location filename="../../src/Global.cpp" line="1089"/>
         <source>Executable &apos;%1&apos; requires Windows 2000 or later.</source>
         <translation type="unfinished">Plik wykonywalny &apos;%1&apos; wymaga do uruchomienia Windows 2000 lub nowszego.</translation>
     </message>
index 5738810..f4ce670 100644 (file)
         <translation>EXE-filen &apos;%1&apos; stöder inte Windows kompatibilitetsläge.</translation>
     </message>
     <message>
-        <location filename="../../src/Global.cpp" line="1059"/>
+        <location filename="../../src/Global.cpp" line="1071"/>
         <source>Executable &apos;%1&apos; requires Qt v%2, but found Qt v%3.</source>
         <translation>EXE-filen &apos;%1&apos; kräver Qt v%2, du har Qt v%3.</translation>
     </message>
     <message>
-        <location filename="../../src/Global.cpp" line="1064"/>
+        <location filename="../../src/Global.cpp" line="1076"/>
         <source>Executable &apos;%1&apos; was built for Qt &apos;%2&apos;, but found Qt &apos;%3&apos;.</source>
         <translation>EXE-filen &apos;%1&apos; är byggd för Qt &apos;%2&apos;, du har Qt &apos;%3&apos;.</translation>
     </message>
     <message>
-        <location filename="../../src/Global.cpp" line="1077"/>
+        <location filename="../../src/Global.cpp" line="1089"/>
         <source>Executable &apos;%1&apos; requires Windows 2000 or later.</source>
         <translation>EXE-filen &apos;%1&apos; kräver Windows 2000 eller senare.</translation>
     </message>
index b77ec89..a8b3436 100644 (file)
@@ -30,7 +30,7 @@
 #define VER_LAMEXP_MINOR_LO                                    5
 #define VER_LAMEXP_TYPE                                                Alpha
 #define VER_LAMEXP_PATCH                                       5
-#define VER_LAMEXP_BUILD                                       1040
+#define VER_LAMEXP_BUILD                                       1042
 
 ///////////////////////////////////////////////////////////////////////////////
 // Tool versions (minimum expected versions!)
index 1d1eea5..d73b199 100644 (file)
@@ -407,7 +407,7 @@ void ProcessingDialog::initEncoding(void)
        unsigned int maximumInstances = qBound(0U, m_settings->maximumInstances(), MAX_INSTANCES);
        if(maximumInstances < 1)
        {
-               lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features();
+               lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features(lamexp_arguments());
                maximumInstances = cores2instances(qBound(1, cpuFeatures.count, 64));
        }
 
index 78b628a..cdef70c 100644 (file)
@@ -625,7 +625,7 @@ void lamexp_init_console(const QStringList &argv)
 /*
  * Detect CPU features
  */
-lamexp_cpu_t lamexp_detect_cpu_features(int argc, char **argv)
+lamexp_cpu_t lamexp_detect_cpu_features(const QStringList &argv)
 {
        typedef BOOL (WINAPI *IsWow64ProcessFun)(__in HANDLE hProcess, __out PBOOL Wow64Process);
        typedef VOID (WINAPI *GetNativeSystemInfoFun)(__out LPSYSTEM_INFO lpSystemInfo);
@@ -720,14 +720,14 @@ lamexp_cpu_t lamexp_detect_cpu_features(int argc, char **argv)
        features.x64 = true;
 #endif
 
-       if((argv != NULL) && (argc > 0))
+       if(argv.count() > 0)
        {
                bool flag = false;
-               for(int i = 0; i < argc; i++)
+               for(int i = 0; i < argv.count(); i++)
                {
-                       if(!_stricmp("--force-cpu-no-64bit", argv[i])) { flag = true; features.x64 = false; }
-                       if(!_stricmp("--force-cpu-no-sse", argv[i])) { flag = true; features.sse = features.sse2 = features.sse3 = features.ssse3 = false; }
-                       if(!_stricmp("--force-cpu-no-intel", argv[i])) { flag = true; features.intel = false; }
+                       if(!argv[i].compare("--force-cpu-no-64bit", Qt::CaseInsensitive)) { flag = true; features.x64 = false; }
+                       if(!argv[i].compare("--force-cpu-no-sse", Qt::CaseInsensitive)) { flag = true; features.sse = features.sse2 = features.sse3 = features.ssse3 = false; }
+                       if(!argv[i].compare("--force-cpu-no-intel", Qt::CaseInsensitive)) { flag = true; features.intel = false; }
                }
                if(flag) qWarning("CPU flags overwritten by user-defined parameters. Take care!\n");
        }
@@ -804,7 +804,7 @@ static HANDLE lamexp_debug_thread_init(void)
 /*
  * Check for compatibility mode
  */
-static bool lamexp_check_compatibility_mode(const char *exportName, const char *executableName)
+static bool lamexp_check_compatibility_mode(const char *exportName, const QString &executableName)
 {
        QLibrary kernel32("kernel32.dll");
 
@@ -813,7 +813,7 @@ static bool lamexp_check_compatibility_mode(const char *exportName, const char *
                if(kernel32.resolve(exportName) != NULL)
                {
                        qWarning("Function '%s' exported from 'kernel32.dll' -> Windows compatibility mode!", exportName);
-                       qFatal("%s", QApplication::tr("Executable '%1' doesn't support Windows compatibility mode.").arg(QString::fromLatin1(executableName)).toLatin1().constData());
+                       qFatal("%s", QApplication::tr("Executable '%1' doesn't support Windows compatibility mode.").arg(executableName).toLatin1().constData());
                        return false;
                }
        }
@@ -1027,6 +1027,7 @@ bool lamexp_init_qt(int argc, char* argv[])
 {
        static bool qt_initialized = false;
        typedef BOOL (WINAPI *SetDllDirectoryProc)(WCHAR *lpPathName);
+       const QStringList &arguments = lamexp_arguments();
 
        //Don't initialized again, if done already
        if(qt_initialized)
@@ -1044,10 +1045,21 @@ bool lamexp_init_qt(int argc, char* argv[])
        }
 
        //Extract executable name from argv[] array
-       char *executableName = argv[0];
-       while(char *temp = strpbrk(executableName, "\\/:?"))
+       QString executableName = QLatin1String("LameXP.exe");
+       if(arguments.count() > 0)
        {
-               executableName = temp + 1;
+               static const char *delimiters = "\\/:?";
+               executableName = arguments[0].trimmed();
+               for(int i = 0; delimiters[i]; i++)
+               {
+                       int temp = executableName.lastIndexOf(QChar(delimiters[i]));
+                       if(temp >= 0) executableName = executableName.mid(temp + 1);
+               }
+               executableName = executableName.trimmed();
+               if(executableName.isEmpty())
+               {
+                       executableName = QLatin1String("LameXP.exe");
+               }
        }
 
        //Check Qt version
@@ -1056,12 +1068,12 @@ bool lamexp_init_qt(int argc, char* argv[])
        qDebug("Compiled with Qt v%s [%s], %s\n", QT_VERSION_STR, QT_PACKAGEDATE_STR, QT_BUILD_KEY);
        if(_stricmp(qVersion(), QT_VERSION_STR))
        {
-               qFatal("%s", QApplication::tr("Executable '%1' requires Qt v%2, but found Qt v%3.").arg(QString::fromLatin1(executableName), QString::fromLatin1(QT_VERSION_STR), QString::fromLatin1(qVersion())).toLatin1().constData());
+               qFatal("%s", QApplication::tr("Executable '%1' requires Qt v%2, but found Qt v%3.").arg(executableName, QString::fromLatin1(QT_VERSION_STR), QString::fromLatin1(qVersion())).toLatin1().constData());
                return false;
        }
        if(QLibraryInfo::buildKey().compare(QString::fromLatin1(QT_BUILD_KEY), Qt::CaseInsensitive))
        {
-               qFatal("%s", QApplication::tr("Executable '%1' was built for Qt '%2', but found Qt '%3'.").arg(QString::fromLatin1(executableName), QString::fromLatin1(QT_BUILD_KEY), QLibraryInfo::buildKey()).toLatin1().constData());
+               qFatal("%s", QApplication::tr("Executable '%1' was built for Qt '%2', but found Qt '%3'.").arg(executableName, QString::fromLatin1(QT_BUILD_KEY), QLibraryInfo::buildKey()).toLatin1().constData());
                return false;
        }
 #else
@@ -1074,7 +1086,7 @@ bool lamexp_init_qt(int argc, char* argv[])
        {
        case 0:
        case QSysInfo::WV_NT:
-               qFatal("%s", QApplication::tr("Executable '%1' requires Windows 2000 or later.").arg(QString::fromLatin1(executableName)).toLatin1().constData());
+               qFatal("%s", QApplication::tr("Executable '%1' requires Windows 2000 or later.").arg(executableName).toLatin1().constData());
                break;
        case QSysInfo::WV_2000:
                qDebug("Running on Windows 2000 (not officially supported!).\n");
@@ -2057,6 +2069,24 @@ QStringList lamexp_available_codepages(bool noAliases)
 }
 
 /*
+ * Application entry point (runs before static initializers)
+ */
+extern "C"
+{
+       int WinMainCRTStartup(void);
+       
+       int lamexp_entry_point(void)
+       {
+               if((!LAMEXP_DEBUG) && lamexp_check_for_debugger())
+               {
+                       FatalAppExit(0, L"Not a debug build. Please unload debugger and try again!");
+                       TerminateProcess(GetCurrentProcess(), -1);
+               }
+               return WinMainCRTStartup();
+       }
+}
+
+/*
  * Finalization function (final clean-up)
  */
 void lamexp_finalization(void)
index f71a750..3ccbd66 100644 (file)
@@ -119,7 +119,7 @@ QString lamexp_rand_str(void);
 const QString &lamexp_temp_folder2(void);
 void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize);
 void lamexp_ipc_send(unsigned int command, const char* message);
-lamexp_cpu_t lamexp_detect_cpu_features(int argc = 0, char **argv = NULL);
+lamexp_cpu_t lamexp_detect_cpu_features(const QStringList &argv);
 bool lamexp_portable_mode(void);
 bool lamexp_shutdown_computer(const QString &message, const unsigned long timeout = 30, const bool forceShutdown = true, const bool hibernate = false);
 bool lamexp_is_hibernation_supported(void);
index 020927f..066ac4c 100644 (file)
@@ -83,7 +83,7 @@ static int lamexp_main(int argc, char* argv[])
        qDebug("");
 
        //Detect CPU capabilities
-       lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features(argc, argv);
+       lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features(arguments);
        qDebug("   CPU vendor id  :  %s (Intel: %s)", cpuFeatures.vendor, LAMEXP_BOOL(cpuFeatures.intel));
        qDebug("CPU brand string  :  %s", cpuFeatures.brand);
        qDebug("   CPU signature  :  Family: %d, Model: %d, Stepping: %d", cpuFeatures.family, cpuFeatures.model, cpuFeatures.stepping);
@@ -131,7 +131,7 @@ static int lamexp_main(int argc, char* argv[])
        //Kill application?
        for(int i = 0; i < argc; i++)
        {
-               if(!_stricmp("--kill", argv[i]) || !_stricmp("--force-kill", argv[i]))
+               if(!arguments[i].compare("--kill", Qt::CaseInsensitive) || !arguments[i].compare("--force-kill", Qt::CaseInsensitive))
                {
                        return 0;
                }
@@ -283,17 +283,3 @@ int main(int argc, char* argv[])
                }
        }
 }
-
-///////////////////////////////////////////////////////////////////////////////
-// CRT initialization
-///////////////////////////////////////////////////////////////////////////////
-
-extern "C"
-{
-       int WinMainCRTStartup(void);
-
-       int lamexp_crt_startup(void)
-       {
-               return WinMainCRTStartup();
-       }
-}