ObjFW  Diff

Differences From Artifact [08b6db7f62]:

To Artifact [fb8661ad24]:


50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64







-
+







#import "OFSystemInfo.h"
#import "OFApplication.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFLocale.h"
#import "OFOnce.h"
#import "OFString.h"
#import "OFURL.h"
#import "OFURI.h"

#if defined(OF_MACOS) || defined(OF_IOS)
# ifdef HAVE_SYSDIR_H
#  include <sysdir.h>
# endif
#endif
#ifdef OF_WINDOWS
238
239
240
241
242
243
244
245

246
247
248
249
250
251

252
253
254
255
256
257
258
238
239
240
241
242
243
244

245
246
247
248
249
250

251
252
253
254
255
256
257
258







-
+





-
+







	operatingSystemVersion = [[OFString alloc]
	    initWithCString: utsname.release
		   encoding: [OFLocale encoding]];
#endif
}

#ifdef OF_NINTENDO_SWITCH
static OFURL *tmpFSURL = nil;
static OFURI *tmpFSURI = nil;

static void
mountTmpFS(void)
{
	if (R_SUCCEEDED(fsdevMountTemporaryStorage("tmpfs")))
		tmpFSURL = [[OFURL alloc] initFileURLWithPath: @"tmpfs:/"
		tmpFSURI = [[OFURI alloc] initFileURIWithPath: @"tmpfs:/"
						  isDirectory: true];
}
#endif

#if defined(OF_X86_64) || defined(OF_X86)
static OF_INLINE struct X86Regs OF_CONST_FUNC
x86CPUID(uint32_t eax, uint32_t ecx)
360
361
362
363
364
365
366
367

368
369
370
371
372
373
374
360
361
362
363
364
365
366

367
368
369
370
371
372
373
374







-
+







{
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFOnce(&onceControl, initOperatingSystemVersion);

	return operatingSystemVersion;
}

+ (OFURL *)userDataURL
+ (OFURI *)userDataURI
{
#ifdef OF_HAVE_FILES
# if defined(OF_MACOS) || defined(OF_IOS)
	char pathC[PATH_MAX];
	OFMutableString *path;

#  ifdef HAVE_SYSDIR_START_SEARCH_PATH_ENUMERATION
402
403
404
405
406
407
408
409

410
411
412
413
414
415
416
417

418
419
420
421
422
423
424
425

426
427
428

429
430
431
432

433
434
435
436
437

438
439
440
441
442
443
444
445
446

447
448
449
450

451
452
453
454
455
456
457

458
459
460
461
462
463
464
402
403
404
405
406
407
408

409
410
411
412
413
414
415
416

417
418
419
420
421
422
423
424

425
426
427

428
429
430
431

432
433
434
435
436

437
438
439
440
441
442
443
444
445

446
447
448
449

450
451
452
453
454
455
456

457
458
459
460
461
462
463
464







-
+







-
+







-
+


-
+



-
+




-
+








-
+



-
+






-
+








		[path deleteCharactersInRange: OFMakeRange(0, 1)];
		[path insertString: home atIndex: 0];
	}

	[path makeImmutable];

	return [OFURL fileURLWithPath: path isDirectory: true];
	return [OFURI fileURIWithPath: path isDirectory: true];
# elif defined(OF_WINDOWS)
	OFDictionary *env = [OFApplication environment];
	OFString *appData;

	if ((appData = [env objectForKey: @"APPDATA"]) == nil)
		return nil;

	return [OFURL fileURLWithPath: appData isDirectory: true];
	return [OFURI fileURIWithPath: appData isDirectory: true];
# elif defined(OF_HAIKU)
	char pathC[PATH_MAX];

	if (find_directory(B_USER_SETTINGS_DIRECTORY, 0, false,
	    pathC, PATH_MAX) != B_OK)
		return nil;

	return [OFURL fileURLWithPath: [OFString stringWithUTF8String: pathC]
	return [OFURI fileURIWithPath: [OFString stringWithUTF8String: pathC]
			  isDirectory: true];
# elif defined(OF_AMIGAOS)
	return [OFURL fileURLWithPath: @"PROGDIR:" isDirectory: true];
	return [OFURI fileURIWithPath: @"PROGDIR:" isDirectory: true];
# else
	OFDictionary *env = [OFApplication environment];
	OFString *var;
	OFURL *URL;
	OFURI *URI;
	void *pool;

	if ((var = [env objectForKey: @"XDG_DATA_HOME"]) != nil &&
	    var.length > 0)
		return [OFURL fileURLWithPath: var isDirectory: true];
		return [OFURI fileURIWithPath: var isDirectory: true];

	if ((var = [env objectForKey: @"HOME"]) == nil)
		return nil;

	pool = objc_autoreleasePoolPush();

	var = [OFString pathWithComponents: [OFArray arrayWithObjects:
	    var, @".local", @"share", nil]];
	URL = [[OFURL alloc] initFileURLWithPath: var isDirectory: true];
	URI = [[OFURI alloc] initFileURIWithPath: var isDirectory: true];

	objc_autoreleasePoolPop(pool);

	return [URL autorelease];
	return [URI autorelease];
# endif
#else
	return nil;
#endif
}

+ (OFURL *)userConfigURL
+ (OFURI *)userConfigURI
{
#ifdef OF_HAVE_FILES
# if defined(OF_MACOS) || defined(OF_IOS)
	char pathC[PATH_MAX];
	OFMutableString *path;

#  ifdef HAVE_SYSDIR_START_SEARCH_PATH_ENUMERATION
492
493
494
495
496
497
498
499

500
501
502
503
504
505
506
507

508
509
510
511
512
513
514
515

516
517
518

519
520
521
522
523
524
525

526
527
528
529
530
531
532

533
534
535
536
537
538
539

540
541
542
543
544
545
546
547
548

549
550
551
552
553
554

555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575

576
577
578
579
580
581
582
583

584
585
586

587
588
589
590
591
592
593

594
595

596
597
598
599
600

601
602
603
604
605
606

607
608

609
610
611
612
613
614
615
492
493
494
495
496
497
498

499
500
501
502
503
504
505
506

507
508
509
510
511
512
513
514

515
516
517

518
519
520
521
522
523
524

525
526
527
528
529
530
531

532
533
534
535
536
537
538

539
540
541
542
543
544
545
546
547

548
549
550
551
552
553

554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574

575
576
577
578
579
580
581
582

583
584
585

586
587
588
589
590
591
592

593
594

595
596
597
598
599

600
601
602
603
604
605

606
607

608
609
610
611
612
613
614
615







-
+







-
+







-
+


-
+






-
+






-
+






-
+








-
+





-
+




















-
+







-
+


-
+






-
+

-
+




-
+





-
+

-
+







		[path deleteCharactersInRange: OFMakeRange(0, 1)];
		[path insertString: home atIndex: 0];
	}

	[path appendString: @"/Preferences"];
	[path makeImmutable];

	return [OFURL fileURLWithPath: path isDirectory: true];
	return [OFURI fileURIWithPath: path isDirectory: true];
# elif defined(OF_WINDOWS)
	OFDictionary *env = [OFApplication environment];
	OFString *appData;

	if ((appData = [env objectForKey: @"APPDATA"]) == nil)
		return nil;

	return [OFURL fileURLWithPath: appData isDirectory: true];
	return [OFURI fileURIWithPath: appData isDirectory: true];
# elif defined(OF_HAIKU)
	char pathC[PATH_MAX];

	if (find_directory(B_USER_SETTINGS_DIRECTORY, 0, false,
	    pathC, PATH_MAX) != B_OK)
		return nil;

	return [OFURL fileURLWithPath: [OFString stringWithUTF8String: pathC]
	return [OFURI fileURIWithPath: [OFString stringWithUTF8String: pathC]
			  isDirectory: true];
# elif defined(OF_AMIGAOS)
	return [OFURL fileURLWithPath: @"PROGDIR:" isDirectory: true];
	return [OFURI fileURIWithPath: @"PROGDIR:" isDirectory: true];
# else
	OFDictionary *env = [OFApplication environment];
	OFString *var;

	if ((var = [env objectForKey: @"XDG_CONFIG_HOME"]) != nil &&
	    var.length > 0)
		return [OFURL fileURLWithPath: var isDirectory: true];
		return [OFURI fileURIWithPath: var isDirectory: true];

	if ((var = [env objectForKey: @"HOME"]) == nil)
		return nil;

	var = [var stringByAppendingPathComponent: @".config"];

	return [OFURL fileURLWithPath: var isDirectory: true];
	return [OFURI fileURIWithPath: var isDirectory: true];
# endif
#else
	return nil;
#endif
}

+ (OFURL *)temporaryDirectoryURL
+ (OFURI *)temporaryDirectoryURI
{
#ifdef OF_HAVE_FILES
# if defined(OF_MACOS) || defined(OF_IOS)
	char buffer[PATH_MAX];
	size_t length;
	OFString *path;

	if ((length = confstr(_CS_DARWIN_USER_TEMP_DIR, buffer, PATH_MAX)) == 0)
		return [OFURL fileURLWithPath: @"/tmp" isDirectory: true];
		return [OFURI fileURIWithPath: @"/tmp" isDirectory: true];

	path = [OFString stringWithCString: buffer
				  encoding: [OFLocale encoding]
				    length: length - 1];

	return [OFURL fileURLWithPath: path isDirectory: true];
	return [OFURI fileURIWithPath: path isDirectory: true];
# elif defined(OF_WINDOWS)
	OFString *path;

	if ([self isWindowsNT]) {
		wchar_t buffer[PATH_MAX];

		if (!GetTempPathW(PATH_MAX, buffer))
			return nil;

		path = [OFString stringWithUTF16String: buffer];
	} else {
		char buffer[PATH_MAX];

		if (!GetTempPathA(PATH_MAX, buffer))
			return nil;

		path = [OFString stringWithCString: buffer
					  encoding: [OFLocale encoding]];
	}

	return [OFURL fileURLWithPath: path isDirectory: true];
	return [OFURI fileURIWithPath: path isDirectory: true];
# elif defined(OF_HAIKU)
	char pathC[PATH_MAX];

	if (find_directory(B_SYSTEM_TEMP_DIRECTORY, 0, false,
	    pathC, PATH_MAX) != B_OK)
		return nil;

	return [OFURL fileURLWithPath: [OFString stringWithUTF8String: pathC]
	return [OFURI fileURIWithPath: [OFString stringWithUTF8String: pathC]
			  isDirectory: true];
# elif defined(OF_AMIGAOS)
	return [OFURL fileURLWithPath: @"T:" isDirectory: true];
	return [OFURI fileURIWithPath: @"T:" isDirectory: true];
# elif defined(OF_MSDOS)
	OFString *path = [[OFApplication environment] objectForKey: @"TEMP"];

	if (path == nil)
		return nil;

	return [OFURL fileURLWithPath: path isDirectory: true];
	return [OFURI fileURIWithPath: path isDirectory: true];
# elif defined(OF_MINT)
	return [OFURL fileURLWithPath: @"u:\\tmp" isDirectory: true];
	return [OFURI fileURIWithPath: @"u:\\tmp" isDirectory: true];
# elif defined(OF_NINTENDO_SWITCH)
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFOnce(&onceControl, mountTmpFS);

	return tmpFSURL;
	return tmpFSURI;
# else
	OFString *path =
	    [[OFApplication environment] objectForKey: @"XDG_RUNTIME_DIR"];

	if (path != nil)
		return [OFURL fileURLWithPath: path];
		return [OFURI fileURIWithPath: path];

	return [OFURL fileURLWithPath: @"/tmp"];
	return [OFURI fileURIWithPath: @"/tmp"];
# endif
#else
	return nil;
#endif
}

+ (OFString *)CPUVendor