44//
55// Project: Sega Dreamcast Project (DreamSDK)
66// Author: The DreamSDK Team (https://dreamsdk.org)
7- // Last Update: 2025-08-16
7+ // Last Update: 2025-08-28
88//
99////////////////////////////////////////////////////////////////////////////////
1010
@@ -224,16 +224,13 @@ function OnLeave_SettingsPage(fwd)
224224function GetSoftwareDevelopmentKitHomeDir()
225225{
226226 local result = ReplaceMacros(_T("$(#DREAMSDK_HOME)"));
227- Trace(_T("GetSoftwareDevelopmentKitHomeDir = ") + result);
228227 return result;
229228}
230229
231230// -----------------------------------------------------------------------------
232231// get the MSYS root base folder for DreamSDK
233232function GetSoftwareDevelopmentKitMsysDir()
234- {
235- Trace(_T("GetSoftwareDevelopmentKitMsysDir"));
236-
233+ {
237234 local result = _T("");
238235 local buffer = _T("");
239236 local filePath = GetSoftwareDevelopmentKitHomeDir()
@@ -244,9 +241,7 @@ function GetSoftwareDevelopmentKitMsysDir()
244241 // used by DreamSDK: MinGW/MSYS (1) or MinGW-w64/MSYS2 (2)
245242 if (IO.FileExists(filePath))
246243 {
247- buffer = IO.ReadFileContents(filePath);
248- Trace(_T("GetSoftwareDevelopmentKitMsysDir: Foundation = ") + buffer);
249-
244+ buffer = IO.ReadFileContents(filePath);
250245 if (buffer.Find(_T("1")) != -1)
251246 {
252247 // MinGW/MSYS
@@ -268,8 +263,7 @@ function GetSoftwareDevelopmentKitMsysDir()
268263 "Sorry, your DreamSDK installation looks like broken.\n" +
269264 "Please reinstall or read the FAQ in the DreamSDK Help."));
270265 }
271-
272- Trace(_T("GetSoftwareDevelopmentKitMsysDir = ") + result);
266+
273267 return result;
274268}
275269
@@ -393,8 +387,12 @@ function InitializeWizard()
393387
394388 Trace(_T("InitializeWizard: ") + configFile);
395389
390+ Trace(_T("SoftwareDevelopmentKitHomeDir: " + GetSoftwareDevelopmentKitHomeDir()));
391+ Trace(_T("SoftwareDevelopmentKitMsysDir: " + GetSoftwareDevelopmentKitMsysDir()));
392+
396393 // Handle DreamSDK IDE helper directory
397394 FileSystemObjects.SoftwareDevelopmentKitHelperDir = GetSoftwareDevelopmentKitHelperDir();
395+ Trace(_T("SoftwareDevelopmentKitHelperDir: " + FileSystemObjects.SoftwareDevelopmentKitHelperDir));
398396 if (!IO.DirectoryExists(FileSystemObjects.SoftwareDevelopmentKitHelperDir))
399397 {
400398 return false;
@@ -419,11 +417,12 @@ function InitializeWizard()
419417 return false;
420418 }
421419 FileSystemObjects.WizardLibraryInformationDir = exportPath;
420+ Trace(_T("WizardLibraryInformationDir: " + FileSystemObjects.WizardLibraryInformationDir));
422421
423422 // Static Files
424423 FileSystemObjects.TemplateStaticFilesDir = FileSystemObjects.WizardBaseDir
425424 + _T("files") + wxFILE_SEP_PATH;
426-
425+
427426 // Dynamic Files
428427 FileSystemObjects.TemplateDynamicFilesDir = FileSystemObjects.WizardBaseDir
429428 + _T("templates") + wxFILE_SEP_PATH;
@@ -473,26 +472,35 @@ function HandleLibraries(project)
473472// add user library information to the project
474473function HandleUserLibraries(project)
475474{
475+ Trace(_T("HandleUserLibraries"));
476+
476477 local separator = _T(":");
477478
478479 local buffer = ::wxArrayString();
479480 local libraries = LibraryInformation.LibraryList;
480481 local sortData = LibraryInformation.LibrarySortList;
481482
482483 // Add libraries name with weight (sort data)
484+ Trace(_T(" Input dataset to sort:"));
483485 for(local i = 0; i < libraries.GetCount(); i++)
484486 {
485487 local library = libraries.Item(i);
486488 local sortIndex = sortData.Item(i);
487- buffer.Add(sortIndex + separator + library, 1);
489+ local sortDataItem = sortIndex + separator + library;
490+ Trace(_T(" " + sortDataItem));
491+ buffer.Add(sortDataItem, 1);
488492 }
489- buffer = JumpDownSort (buffer);
493+ buffer = QuickSort (buffer);
490494
491495 // Everything is now sorted.
492496 // Remove the weight information before adding the libs to the project.
497+ Trace(_T(" Dataset sorted, adding libraries to project:"));
493498 for(local i = 0; i < buffer.GetCount(); i++)
494499 {
495- project.AddLinkLib(buffer.Item(i).AfterFirst(separator));
500+ local library = buffer.Item(i);
501+ Trace(_T(" " + library));
502+ local library = library.AfterFirst(separator);
503+ project.AddLinkLib(library);
496504 }
497505}
498506
@@ -532,33 +540,40 @@ function GetFileLibraryInfo(isLangCPP, fileId)
532540// generate user library information (includes/libs)
533541function GenerateUserLibraryInformation()
534542{
543+ Trace(_T("GenerateUserLibraryInformation"));
544+
535545 LibraryInformation.IncludeBufferText = _T("");
536546 LibraryInformation.IncludeDirectoryList.Clear();
537547 LibraryInformation.LibraryList.Clear();
538548 LibraryInformation.LibrarySortList.Clear();
539-
549+
540550 for (local i = 0; i < ProjectSettings.SelectedLibraryList.GetCount(); i++)
541551 {
542552 local selectedLibraryName = ProjectSettings.SelectedLibraryList.Item(i);
543553 local selectedLibraryIndex = GetReferentialIndex(selectedLibraryName);
554+
555+ Trace(_T(" Handling: ") + selectedLibraryName);
544556
545- // Handle includes
557+ // Handle includes
546558 LibraryInformation.IncludeBufferText = LibraryInformation.IncludeBufferText + _T("\r\n// ") + selectedLibraryName + _T("\r\n");
547559 local libraryInc = GetReferentialInclude(selectedLibraryIndex);
548560 for(local j = 0; j < libraryInc.GetCount(); j++)
549561 {
550562 LibraryInformation.IncludeBufferText = LibraryInformation.IncludeBufferText + _T("#include ") + libraryInc.Item(j) + _T("\r\n");
551- }
563+ }
552564
553565 // Handle include directories
566+ Trace(_T(" Includes Directories:"));
554567 local includeDirectoryList = GetReferentialIncludeDirectory(selectedLibraryIndex);
555568 for(local j = 0; j < includeDirectoryList.GetCount(); j++)
556569 {
557570 local includeDirectory = includeDirectoryList.Item(j);
558571 LibraryInformation.IncludeDirectoryList.Add(includeDirectory, 1);
559- }
572+ Trace(_T(" ") + includeDirectory);
573+ }
560574
561575 // Handle libraries
576+ Trace(_T(" Libraries:"));
562577 local libraryNameList = GetReferentialLibrary(selectedLibraryIndex);
563578 local librarySortList = GetReferentialLibrarySortIndex(selectedLibraryIndex);
564579 for(local j = 0; j < libraryNameList.GetCount(); j++)
@@ -567,6 +582,7 @@ function GenerateUserLibraryInformation()
567582 local librarySortIndex = librarySortList.Item(j);
568583 LibraryInformation.LibraryList.Add(libraryName, 1);
569584 LibraryInformation.LibrarySortList.Add(librarySortIndex, 1);
585+ Trace(_T(" ") + libraryName);
570586 }
571587 }
572588}
@@ -749,19 +765,105 @@ function HandleDirective(buffer, directive, enabled)
749765}
750766
751767// -----------------------------------------------------------------------------
752- // sort an wxArrayString (or any array type) using the jump-down sort algorithm.
768+ // sort an wxArrayString (or any array type) using the jump-down sort algorithm
753769function JumpDownSort(array)
754770{
755- for(local i = array.GetCount() - 1; i > 0; i--)
756- for(local j = 0; j < i; j++)
757- if (array.Item(i) < array.Item(j))
758- {
759- local tmp = array.Item(i);
760- array.SetItem(i, array.Item(j));
761- array.SetItem(j, tmp);
762- }
771+ local n = array.GetCount();
772+ local tmp = [];
763773
764- return array;
774+ // extract all wxStrings as pure strings
775+ for (local i = 0; i < n; i++)
776+ tmp.append(array.Item(i).tostring());
777+
778+ // standard insertion sort (pure strings)
779+ for (local i = 1; i < n; i++)
780+ {
781+ local key = tmp[i];
782+ local j = i - 1;
783+ while (j >= 0 && tmp[j] > key)
784+ {
785+ tmp[j + 1] = tmp[j];
786+ j--;
787+ }
788+ tmp[j + 1] = key;
789+ }
790+
791+ // clear original array and refill
792+ array.Clear();
793+ foreach (s in tmp)
794+ array.Add(_T(s), 1);
795+
796+ return array;
797+ }
798+
799+ // -----------------------------------------------------------------------------
800+ // sort an wxArrayString (or any array type) using the quick sort algorithm
801+ function QuickSort(array)
802+ {
803+ local n = array.GetCount();
804+ local tmp = [];
805+
806+ // Extract all wxStrings as pure strings
807+ for (local i = 0; i < n; i++)
808+ tmp.append(array.Item(i).tostring());
809+
810+ // Iterative QuickSort
811+ function partition(lst, low, high)
812+ {
813+ local pivot = lst[(low + high) / 2];
814+ local i = low;
815+ local j = high;
816+
817+ while (i <= j)
818+ {
819+ while (lst[i] < pivot) i++;
820+ while (lst[j] > pivot) j--;
821+
822+ if (i <= j)
823+ {
824+ local t = lst[i];
825+ lst[i] = lst[j];
826+ lst[j] = t;
827+ i++;
828+ j--;
829+ }
830+ }
831+ return [i, j];
832+ }
833+
834+ function quicksort_iter(lst)
835+ {
836+ local stack = [];
837+ stack.append([0, lst.len() - 1]);
838+
839+ while (stack.len() > 0)
840+ {
841+ local range = stack.pop();
842+ local low = range[0];
843+ local high = range[1];
844+
845+ if (low < high)
846+ {
847+ local res = partition(lst, low, high);
848+ local i = res[0];
849+ local j = res[1];
850+
851+ // Push sub-ranges onto stack
852+ if (low < j) stack.append([low, j]);
853+ if (i < high) stack.append([i, high]);
854+ }
855+ }
856+ }
857+
858+ // Perform QuickSort on tmp
859+ quicksort_iter(tmp);
860+
861+ // Clear original array and refill
862+ array.Clear();
863+ foreach (s in tmp)
864+ array.Add(_T(s), 1); // wxWidgets conversion
865+
866+ return array;
765867}
766868
767869// -----------------------------------------------------------------------------
0 commit comments