// File: /workspace/github_c_makefile_star2_O3/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 $0x1d8, %rsp            # imm = 0x1D8
movl %esi, %r15d
movq %rdi, 0x38(%rsp)
movb 0xc45bb(%rip), %al      # 0x176130
testb %al, %al
je 0xb2052
movl %r15d, %eax
leaq (%rax,%rax,2), %rax
leaq 0xc4515(%rip), %rcx     # 0x1760a0
leaq (%rcx,%rax,8), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x56bd0
testb %al, %al
je 0xb1bb5
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x570b0
movq %rbx, %rax
jmp 0xb2040
leaq 0x6071a(%rip), %rsi     # 0x1122d6
leaq 0xb8(%rsp), %rdi
callq 0x590d0
callq 0x56090
movl %eax, %edi
callq 0x559b0
testq %rax, %rax
je 0xb1be8
movq 0x20(%rax), %rsi
movq %r14, %rdi
callq 0x55f40
jmp 0xb1bf7
leaq 0x4165d(%rip), %rsi     # 0xf324c
movq %r14, %rdi
callq 0x55f40
leaq 0x60c60(%rip), %rdi     # 0x11285e
callq 0x57720
leaq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x579f0
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
callq 0x55260
testb %al, %al
je 0xb1c77
leaq 0xd0(%rsp), %rdi
movq %r14, %rsi
callq 0x570b0
leaq 0x60c37(%rip), %rsi     # 0x11286e
leaq 0x8(%rsp), %rdi
callq 0x579f0
leaq 0xd0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x562f0
leaq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x555f0
leaq 0x8(%rsp), %rdi
callq 0x59200
leaq 0xd0(%rsp), %rdi
callq 0x59200
leaq 0x8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x570b0
leaq 0x60c01(%rip), %rsi     # 0x11288e
leaq 0x20(%rsp), %rdi
callq 0x579f0
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x562f0
movq %rax, %r12
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x58e20
leaq 0xd0(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %r12, %rsi
callq 0x56800
leaq 0xd0(%rsp), %rdi
callq 0x56ef0
movl %eax, %ebp
leaq 0xd0(%rsp), %rdi
callq 0x59178
leaq 0x40(%rsp), %rdi
callq 0x59200
leaq 0x20(%rsp), %rdi
callq 0x59200
leaq 0x8(%rsp), %rdi
callq 0x59200
testb %bpl, %bpl
je 0xb1f8e
leaq 0x8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x570b0
leaq 0x60b6b(%rip), %rsi     # 0x11288e
leaq 0x20(%rsp), %rdi
callq 0x579f0
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x562f0
leaq 0xd0(%rsp), %rdi
movl $0x3, %esi
movq %rax, %rdx
movl $0x2, %ecx
callq 0x58730
leaq 0x20(%rsp), %rdi
callq 0x59200
leaq 0x8(%rsp), %rdi
callq 0x59200
cmpw $0x0, 0xd8(%rsp)
je 0xb1e76
leaq 0x8(%rsp), %r12
decl %r15d
leaq 0x6081c(%rip), %r13     # 0x1125a4
leaq 0x20(%rsp), %rbp
movq 0x118(%rsp), %rax
cmpq 0xe0(%rsp), %rax
jge 0xb1f81
movq %r12, %rdi
leaq 0xd0(%rsp), %rsi
callq 0x57310
cmpl $0x4, %r15d
ja 0xb1e5f
movslq (%r13,%r15,4), %rax
addq %r13, %rax
jmpq *%rax
movq %rbp, %rdi
leaq 0x60acd(%rip), %rsi     # 0x11289e
callq 0x579f0
movq %r12, %rdi
movq %rbp, %rsi
callq 0x577d0
jmp 0xb1e51
movq %rbp, %rdi
leaq 0x60af1(%rip), %rsi     # 0x1128de
callq 0x579f0
movq %r12, %rdi
movq %rbp, %rsi
callq 0x577d0
jmp 0xb1e51
movq %rbp, %rdi
leaq 0x60ab8(%rip), %rsi     # 0x1128c1
callq 0x579f0
movq %r12, %rdi
movq %rbp, %rsi
callq 0x577d0
jmp 0xb1e51
movq %rbp, %rdi
leaq 0x60aaa(%rip), %rsi     # 0x1128cf
callq 0x579f0
movq %r12, %rdi
movq %rbp, %rsi
callq 0x577d0
jmp 0xb1e51
movq %rbp, %rdi
leaq 0x60a6f(%rip), %rsi     # 0x1128b0
callq 0x579f0
movq %r12, %rdi
movq %rbp, %rsi
callq 0x577d0
movl %eax, %ebx
movq %rbp, %rdi
callq 0x59200
testb %bl, %bl
jne 0xb1e85
movq %r12, %rdi
callq 0x59200
cmpw $0x0, 0xd8(%rsp)
jne 0xb1d8d
movw $0x5, 0x1c8(%rsp)
jmp 0xb1f81
leaq 0x609d0(%rip), %rsi     # 0x11285c
leaq 0x40(%rsp), %rdi
callq 0x579f0
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x57610
movl %eax, %ebp
leaq 0x609ae(%rip), %rsi     # 0x11285c
leaq 0xa0(%rsp), %rdi
callq 0x579f0
leaq 0x8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x58a10
movl %eax, %r15d
leaq 0x60985(%rip), %rsi     # 0x11285c
leaq 0x88(%rsp), %rdi
callq 0x579f0
leaq 0x8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x57610
incl %ebp
notl %eax
addl %eax, %r15d
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x58f50
leaq 0x609d7(%rip), %rsi     # 0x1128ef
leaq 0x70(%rsp), %rdi
callq 0x579f0
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movq %r14, %rdx
callq 0x575f0
movq %r14, %rdi
movq %rax, %rsi
callq 0x555f0
leaq 0x70(%rsp), %rdi
callq 0x59200
leaq 0x20(%rsp), %rdi
callq 0x59200
leaq 0x88(%rsp), %rdi
callq 0x59200
leaq 0xa0(%rsp), %rdi
callq 0x59200
leaq 0x40(%rsp), %rdi
callq 0x59200
leaq 0x8(%rsp), %rdi
callq 0x59200
leaq 0xd0(%rsp), %rdi
callq 0x555b0
callq 0x55370
leaq 0xd0(%rsp), %rdi
movq %rax, %rsi
callq 0x579f0
leaq 0xd0(%rsp), %rsi
movq %r14, %rdi
callq 0x58b10
movl %eax, %ebp
leaq 0xd0(%rsp), %rdi
callq 0x59200
testb %bpl, %bpl
jne 0xb1ff9
callq 0x55370
leaq 0xd0(%rsp), %rdi
movq %rax, %rsi
callq 0x579f0
leaq 0xd0(%rsp), %rsi
movq %r14, %rdi
callq 0x562f0
leaq 0xd0(%rsp), %rdi
callq 0x59200
callq 0x55370
movq %r14, %rdi
movq %rax, %rsi
callq 0x57ef0
testb %al, %al
je 0xb2017
movq %r14, %rdi
xorl %esi, %esi
callq 0x579e0
movq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x570b0
leaq 0x58(%rsp), %rdi
callq 0x59200
leaq 0xb8(%rsp), %rdi
callq 0x56a30
movq 0x38(%rsp), %rax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc40d7(%rip), %rdi     # 0x176130
callq 0x56120
testl %eax, %eax
je 0xb1b7d
xorl %r14d, %r14d
leaq 0xc4030(%rip), %r12     # 0x1760a0
leaq (%r12,%r14), %rdi
xorl %esi, %esi
callq 0x58e20
addq $0x18, %r14
cmpq $0x90, %r14
jne 0xb2070
leaq -0x57c8f(%rip), %rdi    # 0x5a400
leaq 0xbbfea(%rip), %rdx     # 0x16e080
xorl %esi, %esi
callq 0x57e10
leaq 0xc408c(%rip), %rdi     # 0x176130
callq 0x56b80
jmp 0xb1b7d
movq %rax, %rbx
testq %r14, %r14
je 0xb20c9
leaq (%r14,%r12), %rdi
addq $-0x18, %rdi
callq 0x59200
addq $-0x18, %r14
jne 0xb20b6
leaq 0xc4060(%rip), %rdi     # 0x176130
callq 0x56420
jmp 0xb2202
movq %rax, %rbx
jmp 0xb20fc
jmp 0xb20e1
movq %rax, %rbx
jmp 0xb2118
jmp 0xb20e8
movq %rax, %rbx
jmp 0xb2125
jmp 0xb215b
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x59200
leaq 0x20(%rsp), %rdi
callq 0x59200
jmp 0xb210b
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x59200
leaq 0xa0(%rsp), %rdi
callq 0x59200
leaq 0x40(%rsp), %rdi
jmp 0xb2154
jmp 0xb216c
jmp 0xb21a5
jmp 0xb21e8
jmp 0xb216c
jmp 0xb21e8
jmp 0xb214c
jmp 0xb215b
jmp 0xb214c
jmp 0xb215b
jmp 0xb214c
jmp 0xb215b
jmp 0xb214c
jmp 0xb215b
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x59200
jmp 0xb215e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x59200
jmp 0xb21d9
jmp 0xb21e8
movq %rax, %rbx
jmp 0xb21bc
jmp 0xb2196
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x59178
jmp 0xb2188
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x59200
jmp 0xb2199
jmp 0xb2196
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x59200
jmp 0xb21a8
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0xb21c4
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x59200
leaq 0xd0(%rsp), %rdi
callq 0x59200
jmp 0xb21eb
jmp 0xb21e8
jmp 0xb21d1
jmp 0xb21e8
movq %rax, %rbx
jmp 0xb21f5
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x555b0
jmp 0xb21eb
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x59200
leaq 0xb8(%rsp), %rdi
callq 0x56a30
movq %rbx, %rdi
callq 0x57090