// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/classes/system/system.cpp
// Function: smooth::System::System::GetPersonalFilesDirectory(smooth::System::PersonalFilesType)
S::String S::System::System::GetPersonalFilesDirectory(PersonalFilesType type)
{
	static String	 personalDir[NumPersonalFilesTypes];

	if (personalDir[type] != NIL) return personalDir[type];

	String::InputFormat	 inputFormat("UTF-8");

#ifdef __WIN32__
	ITEMIDLIST	*idlist;
	Buffer<wchar_t>	 buffer(32768 + 1);

	switch (type)
	{
		default:
		case PersonalFilesGeneric:
			SHGetSpecialFolderLocation(NIL, CSIDL_PROFILE, &idlist);
			break;
		case PersonalFilesDocuments:
			SHGetSpecialFolderLocation(NIL, CSIDL_PERSONAL, &idlist);
			break;
		case PersonalFilesPictures:
			SHGetSpecialFolderLocation(NIL, CSIDL_MYPICTURES, &idlist);
			break;
		case PersonalFilesMusic:
			SHGetSpecialFolderLocation(NIL, CSIDL_MYMUSIC, &idlist);
			break;
		case PersonalFilesMovies:
			if (Backends::BackendWin32::IsWindowsVersionAtLeast(VER_PLATFORM_WIN32_NT, 5, 1)) SHGetSpecialFolderLocation(NIL, CSIDL_MYVIDEO, &idlist);
			else										  SHGetSpecialFolderLocation(NIL, CSIDL_PERSONAL, &idlist);
			break;
		case PersonalFilesDownloads:
			SHGetSpecialFolderLocation(NIL, CSIDL_PERSONAL, &idlist);
			break;
	}

	SHGetPathFromIDList(idlist, buffer);

	personalDir[type] = buffer;

	CoTaskMemFree(idlist);

	if (personalDir[type] == NIL) personalDir[type] = "C:";
#else
	passwd	*pw = getpwuid(getuid());

	if (pw != NIL)	personalDir[type] = pw->pw_dir;
	else		personalDir[type] = "~";

#ifdef __APPLE__
	OSErr	 error = -1;
	FSRef	 entry;

	switch (type)
	{
		default:
		case PersonalFilesGeneric:
			break;
		case PersonalFilesDocuments:
			error = FSFindFolder(kUserDomain, kDocumentsFolderType, kDontCreateFolder, &entry);
			break;
		case PersonalFilesPictures:
			error = FSFindFolder(kUserDomain, kPictureDocumentsFolderType, kDontCreateFolder, &entry);
			break;
		case PersonalFilesMusic:
			error = FSFindFolder(kUserDomain, kMusicDocumentsFolderType, kDontCreateFolder, &entry);
			break;
		case PersonalFilesMovies:
			error = FSFindFolder(kUserDomain, kMovieDocumentsFolderType, kDontCreateFolder, &entry);
			break;
		case PersonalFilesDownloads:
			break;
	}

	if (error == noErr)
	{
		CFURLRef	 url = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &entry);

		if (url != NIL)
		{
			CFStringRef	 path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);

			if (path != NIL)
			{
				Buffer<char>	 buffer(CFStringGetLength(path) * 4 + 1);

				CFStringGetCString(path, buffer, buffer.Size(), kCFStringEncodingUTF8);

				personalDir[type] = buffer;

				CFRelease(path);
			}

			CFRelease(url);
		}
	}
#else
	String	 configHome = getenv("XDG_CONFIG_HOME");

	if (configHome == NIL) configHome = String(personalDir[type]).Append("/.config");

	if (File(String(configHome).Append("/user-dirs.dirs")).Exists())
	{
		IO::InStream	 in(IO::STREAM_FILE, String(configHome).Append("/user-dirs.dirs"), IO::IS_READ);

		while (in.GetPos() < in.Size())
		{
			String	 entry = in.InputLine();

			if ((type == PersonalFilesDocuments && entry.StartsWith("XDG_DOCUMENTS_DIR")) ||
			    (type == PersonalFilesPictures  && entry.StartsWith("XDG_PICTURES_DIR" )) ||
			    (type == PersonalFilesMusic	    && entry.StartsWith("XDG_MUSIC_DIR"	   )) ||
			    (type == PersonalFilesMovies    && entry.StartsWith("XDG_VIDEOS_DIR"   )) ||
			    (type == PersonalFilesDownloads && entry.StartsWith("XDG_DOWNLOAD_DIR" )))
			{
				personalDir[type] = entry.SubString(entry.Find("\"") + 1, entry.FindLast("\"") - entry.Find("\"") - 1).Replace("$HOME", personalDir[type]);

				break;
			}
		}
	}
#endif
#endif

	if (!personalDir[type].EndsWith(Directory::GetDirectoryDelimiter())) personalDir[type].Append(Directory::GetDirectoryDelimiter());
	if ( personalDir[type] == Directory::GetDirectoryDelimiter())	     personalDir[type] = NIL;

	return personalDir[type];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movl %esi, %ebp
movq %rdi, 0x20(%rsp)
movb 0xc47d0(%rip), %al      # 0x177130
testb %al, %al
movl %esi, 0x4(%rsp)
je 0xb2f91
movl %ebp, %eax
leaq (%rax,%rax,2), %rax
leaq 0xc4727(%rip), %rcx     # 0x1770a0
leaq (%rcx,%rax,8), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x56bd0
testb %al, %al
je 0xb29a3
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x570b0
movq %rbx, %rax
jmp 0xb2f7f
leaq 0x6077c(%rip), %rsi     # 0x113126
leaq 0x138(%rsp), %rdi
callq 0x590d0
callq 0x56090
movl %eax, %edi
callq 0x559b0
testq %rax, %rax
je 0xb29d6
movq 0x20(%rax), %rsi
movq %r14, %rdi
callq 0x55f40
jmp 0xb29e5
leaq 0x4186f(%rip), %rsi     # 0xf424c
movq %r14, %rdi
callq 0x55f40
leaq 0x60cad(%rip), %rdi     # 0x113699
callq 0x57720
leaq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x579f0
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x55260
testb %al, %al
je 0xb2a65
leaq 0x150(%rsp), %rdi
movq %r14, %rsi
callq 0x570b0
leaq 0x60c84(%rip), %rsi     # 0x1136a9
leaq 0x8(%rsp), %rdi
callq 0x579f0
leaq 0x150(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x562f0
leaq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x555f0
leaq 0x8(%rsp), %rdi
callq 0x59200
leaq 0x150(%rsp), %rdi
callq 0x59200
leaq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x570b0
leaq 0x60c4e(%rip), %rsi     # 0x1136c9
leaq 0x28(%rsp), %rdi
callq 0x579f0
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x562f0
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x58e20
leaq 0x150(%rsp), %rdi
leaq 0x48(%rsp), %rdx
movq %rbx, %rsi
callq 0x56800
leaq 0x150(%rsp), %rdi
callq 0x56ef0
movl %eax, %ebx
leaq 0x150(%rsp), %rdi
callq 0x59178
leaq 0x48(%rsp), %rdi
callq 0x59200
leaq 0x28(%rsp), %rdi
callq 0x59200
leaq 0x8(%rsp), %rdi
callq 0x59200
testb %bl, %bl
je 0xb2ece
leaq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x570b0
leaq 0x60bb9(%rip), %rsi     # 0x1136c9
leaq 0x28(%rsp), %rdi
callq 0x579f0
movq %r14, 0x40(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x562f0
leaq 0x150(%rsp), %rdi
movl $0x3, %esi
movq %rax, %rdx
movl $0x2, %ecx
callq 0x58730
leaq 0x28(%rsp), %rdi
callq 0x59200
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x59200
cmpl $0x1, %ebp
sete (%rsp)
cmpl $0x2, %ebp
sete 0x1(%rsp)
cmpl $0x3, %ebp
sete 0x2(%rsp)
cmpl $0x4, %ebp
sete 0x3(%rsp)
movzwl 0x158(%rsp), %ecx
testw %cx, %cx
je 0xb2b95
movq 0x198(%rsp), %rax
jmp 0xb2ba6
movw $0x5, 0x248(%rsp)
movq $-0x1, %rax
testw %cx, %cx
je 0xb2bb5
movq 0x160(%rsp), %rcx
jmp 0xb2bc6
movw $0x5, 0x248(%rsp)
movq $-0x1, %rcx
cmpq %rcx, %rax
jge 0xb2ebc
movq %r12, %rdi
leaq 0x150(%rsp), %rsi
callq 0x57310
cmpl $0x1, %ebp
leaq 0x28(%rsp), %rbx
leaq 0x108(%rsp), %r14
jne 0xb2c1a
movq %rbx, %rdi
leaq 0x60ade(%rip), %rsi     # 0x1136d9
callq 0x579f0
movq %r12, %rdi
movq %rbx, %rsi
callq 0x577d0
testb %al, %al
je 0xb2c1a
movb $0x1, %r15b
xorl %r13d, %r13d
xorl %r14d, %r14d
jmp 0xb2c4c
cmpl $0x2, %ebp
jne 0xb2c50
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
leaq 0x60abd(%rip), %rsi     # 0x1136eb
callq 0x579f0
movq %r12, %rdi
movq %rbx, %rsi
callq 0x577d0
testb %al, %al
je 0xb2c50
movb $0x1, %r13b
xorl %r14d, %r14d
movb (%rsp), %r15b
xorl %ebp, %ebp
jmp 0xb2c93
cmpl $0x3, %ebp
jne 0xb2e14
leaq 0x120(%rsp), %rbx
movq %rbx, %rdi
leaq 0x60a91(%rip), %rsi     # 0x1136fc
callq 0x579f0
movq %r12, %rdi
movq %rbx, %rsi
callq 0x577d0
testb %al, %al
je 0xb2e14
movb $0x1, %r14b
xorl %ebp, %ebp
movb (%rsp), %r15b
movb 0x1(%rsp), %al
movl %eax, %r13d
xorl %eax, %eax
movb $0x1, %bl
testb %al, %al
je 0xb2ca8
leaq 0xf0(%rsp), %rdi
callq 0x59200
testb %bpl, %bpl
je 0xb2cba
leaq 0x108(%rsp), %rdi
callq 0x59200
testb %r14b, %r14b
movl 0x4(%rsp), %ebp
je 0xb2cd0
leaq 0x120(%rsp), %rdi
callq 0x59200
testb %r13b, %r13b
je 0xb2cdf
leaq 0x48(%rsp), %rdi
callq 0x59200
testb %r15b, %r15b
je 0xb2cee
leaq 0x28(%rsp), %rdi
callq 0x59200
testb %bl, %bl
je 0xb2e07
leaq 0xd8(%rsp), %r15
movq %r15, %rdi
leaq 0x6098f(%rip), %rsi     # 0x113697
callq 0x579f0
movq %r12, %rdi
movq %r15, %rsi
callq 0x57610
movl %eax, %r13d
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
leaq 0x6096a(%rip), %rsi     # 0x113697
callq 0x579f0
movq %r12, %rdi
movq %r15, %rsi
callq 0x58a10
movl %eax, %r15d
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
leaq 0x60945(%rip), %rsi     # 0x113697
callq 0x579f0
movq %r12, %rdi
movq %r14, %rsi
callq 0x57610
incl %r13d
notl %eax
addl %eax, %r15d
leaq 0x78(%rsp), %rdi
movq %r12, %rsi
movl %r13d, %edx
movl %r15d, %ecx
callq 0x58f50
leaq 0x90(%rsp), %r14
movq %r14, %rdi
leaq 0x6099b(%rip), %rsi     # 0x11372a
callq 0x579f0
leaq 0x78(%rsp), %rdi
movq %r14, %rsi
movq 0x40(%rsp), %r14
movq %r14, %rdx
callq 0x575f0
movq %r14, %rdi
movq %rax, %rsi
callq 0x555f0
leaq 0x90(%rsp), %rdi
callq 0x59200
leaq 0x78(%rsp), %rdi
callq 0x59200
leaq 0xa8(%rsp), %rdi
callq 0x59200
leaq 0xc0(%rsp), %rdi
callq 0x59200
leaq 0xd8(%rsp), %rdi
callq 0x59200
movq %r12, %rdi
callq 0x59200
testb %bl, %bl
je 0xb2b7e
jmp 0xb2ebc
movq %r12, %rdi
callq 0x59200
jmp 0xb2b7e
cmpl $0x4, %ebp
jne 0xb2e53
movq %r14, %rdi
leaq 0x608e7(%rip), %rsi     # 0x11370a
callq 0x579f0
movq %r12, %rdi
movq %r14, %rsi
callq 0x577d0
testb %al, %al
je 0xb2e53
movb $0x1, %bpl
xorl %eax, %eax
movb (%rsp), %r15b
movb 0x1(%rsp), %cl
movl %ecx, %r13d
movb 0x2(%rsp), %cl
movl %ecx, %r14d
jmp 0xb2c95
cmpl $0x5, %ebp
jne 0xb2e9b
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x608af(%rip), %rsi     # 0x113719
callq 0x579f0
movq %r12, %rdi
movq %rbx, %rsi
callq 0x577d0
movl %eax, %ebx
movb $0x1, %al
movb (%rsp), %r15b
movb 0x1(%rsp), %cl
movl %ecx, %r13d
movb 0x2(%rsp), %cl
movl %ecx, %r14d
movb 0x3(%rsp), %cl
movl %ecx, %ebp
jmp 0xb2c97
xorl %eax, %eax
movb (%rsp), %r15b
movb 0x1(%rsp), %cl
movl %ecx, %r13d
movb 0x2(%rsp), %cl
movl %ecx, %r14d
movb 0x3(%rsp), %cl
movl %ecx, %ebp
xorl %ebx, %ebx
jmp 0xb2c97
leaq 0x150(%rsp), %rdi
callq 0x555b0
movq 0x40(%rsp), %r14
callq 0x55370
leaq 0x150(%rsp), %rdi
movq %rax, %rsi
callq 0x579f0
leaq 0x150(%rsp), %rsi
movq %r14, %rdi
callq 0x58b10
movl %eax, %ebx
leaq 0x150(%rsp), %rdi
callq 0x59200
testb %bl, %bl
jne 0xb2f38
callq 0x55370
leaq 0x150(%rsp), %rdi
movq %rax, %rsi
callq 0x579f0
leaq 0x150(%rsp), %rsi
movq %r14, %rdi
callq 0x562f0
leaq 0x150(%rsp), %rdi
callq 0x59200
callq 0x55370
movq %r14, %rdi
movq %rax, %rsi
callq 0x57ef0
testb %al, %al
je 0xb2f56
movq %r14, %rdi
xorl %esi, %esi
callq 0x579e0
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x570b0
leaq 0x60(%rsp), %rdi
callq 0x59200
leaq 0x138(%rsp), %rdi
callq 0x56a30
movq 0x20(%rsp), %rax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc4198(%rip), %rdi     # 0x177130
callq 0x56120
testl %eax, %eax
je 0xb296c
xorl %r14d, %r14d
leaq 0xc40f1(%rip), %r15     # 0x1770a0
leaq (%r15,%r14), %rdi
xorl %esi, %esi
callq 0x58e20
addq $0x18, %r14
cmpq $0x90, %r14
jne 0xb2faf
leaq -0x58bcd(%rip), %rdi    # 0x5a401
leaq 0xbc0ab(%rip), %rdx     # 0x16f080
xorl %esi, %esi
callq 0x57e10
leaq 0xc414d(%rip), %rdi     # 0x177130
callq 0x56b80
movl 0x4(%rsp), %ebp
jmp 0xb296c
movq %rax, %rbx
testq %r14, %r14
je 0xb300c
leaq (%r14,%r15), %rdi
addq $-0x18, %rdi
callq 0x59200
addq $-0x18, %r14
jne 0xb2ff9
leaq 0xc411d(%rip), %rdi     # 0x177130
callq 0x56420
jmp 0xb3202
jmp 0xb3032
jmp 0xb306b
jmp 0xb3153
jmp 0xb3032
jmp 0xb3153
jmp 0xb3153
movq %rax, %rbx
jmp 0xb3082
jmp 0xb305c
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0x59178
jmp 0xb304e
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x59200
jmp 0xb305f
jmp 0xb305c
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x59200
jmp 0xb306e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0xb308a
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x59200
leaq 0x150(%rsp), %rdi
callq 0x59200
jmp 0xb31eb
jmp 0xb3153
jmp 0xb30b7
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x59200
jmp 0xb30c7
movq %rax, %rbx
jmp 0xb30c7
jmp 0xb3153
movq %rax, %rbx
jmp 0xb31f5
movq %rax, %rbx
movb $0x1, 0x3(%rsp)
cmpb $0x0, 0x3(%rsp)
je 0xb30e5
leaq 0x108(%rsp), %rdi
callq 0x59200
jmp 0xb30e5
movq %rax, %rbx
movb $0x1, 0x3(%rsp)
cmpb $0x0, 0x3(%rsp)
jmp 0xb30f4
movq %rax, %rbx
movb $0x1, 0x2(%rsp)
cmpb $0x0, 0x2(%rsp)
je 0xb3112
leaq 0x120(%rsp), %rdi
callq 0x59200
jmp 0xb3112
movq %rax, %rbx
movb $0x1, 0x2(%rsp)
cmpb $0x0, 0x2(%rsp)
jmp 0xb3121
movq %rax, %rbx
movb $0x1, 0x1(%rsp)
cmpb $0x0, 0x1(%rsp)
je 0xb313c
leaq 0x48(%rsp), %rdi
callq 0x59200
jmp 0xb313c
movq %rax, %rbx
movb $0x1, 0x1(%rsp)
cmpb $0x0, 0x1(%rsp)
cmpb $0x0, (%rsp)
je 0xb3172
leaq 0x28(%rsp), %rdi
callq 0x59200
jmp 0xb3172
movq %rax, %rbx
jmp 0xb31eb
movq %rax, %rbx
jmp 0xb31d4
movq %rax, %rbx
movb $0x1, (%rsp)
jmp 0xb3141
jmp 0xb3178
movq %rax, %rbx
movb $0x1, (%rsp)
cmpb $0x0, (%rsp)
jmp 0xb31d4
movq %rax, %rbx
jmp 0xb31ba
movq %rax, %rbx
jmp 0xb319e
jmp 0xb3184
movq %rax, %rbx
jmp 0xb31c7
movq %rax, %rbx
jmp 0xb31de
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x59200
leaq 0x78(%rsp), %rdi
callq 0x59200
jmp 0xb31ad
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x59200
leaq 0xc0(%rsp), %rdi
callq 0x59200
leaq 0xd8(%rsp), %rdi
callq 0x59200
leaq 0x8(%rsp), %rdi
callq 0x59200
leaq 0x150(%rsp), %rdi
callq 0x555b0
leaq 0x60(%rsp), %rdi
callq 0x59200
leaq 0x138(%rsp), %rdi
callq 0x56a30
movq %rbx, %rdi
callq 0x57090