From a2083b31e3692c97c3f74291d94b4fbb32a36cc6 Mon Sep 17 00:00:00 2001 From: oy Date: Thu, 16 Sep 2010 12:48:32 +0200 Subject: fixed last commit --- src/base/system.c | 15 ++++++------- src/base/system.h | 8 ++++--- src/game/client/components/menus_demo.cpp | 4 +--- src/game/editor/ed_editor.cpp | 36 +++++++++++++++++++++++++++---- src/game/editor/ed_editor.h | 6 +++--- 5 files changed, 48 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/base/system.c b/src/base/system.c index 9a291045..5312a705 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -984,18 +984,17 @@ int fs_chdir(const char *path) return 1; } -void fs_parent_dir(const char *path, char *buffer) +void fs_parent_dir(char *path) { - int stop = 0; - int i = 0; - for(i = 0; i < 256; i++) + char *parent = 0; + for(; *path; ++path) { - if(path[i] == '/') - stop = i+1; + if(*path == '/' || *path == '\\') + parent = path; } - //keep the chars which are before the last '/' and remove the chars which are after - str_copy(buffer, path, stop); + if(parent) + *parent = 0; } void swap_endian(void *data, unsigned elem_size, unsigned num) diff --git a/src/base/system.h b/src/base/system.h index c9d25260..e55e2ad7 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -949,10 +949,12 @@ int fs_chdir(const char *path); Get the parent directory of a directory Parameters: - path - The directory - buffer - Buffer to set the parent folder + path - The directory string + + Remarks: + - The string is treated as zero-termineted string. */ -void fs_parent_dir(const char *path, char *buffer); +void fs_parent_dir(char *path); /* Group: Undocumented diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index c5e6ee97..a5ca860a 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -529,9 +529,7 @@ void CMenus::RenderDemoList(CUIRect MainView) { if(str_comp(m_lDemos[s_SelectedItem].m_aName, "..") == 0) //parent folder { - char aParentFolder[256]; - fs_parent_dir(m_aCurrentDemoFolder, aParentFolder); - str_copy(m_aCurrentDemoFolder, aParentFolder, sizeof(m_aCurrentDemoFolder)); + fs_parent_dir(m_aCurrentDemoFolder); DemolistPopulate(); s_SelectedItem = m_lDemos.size() > 0 ? 0 : -1; } diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index 9a997ce9..a8e3b832 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -567,13 +567,12 @@ static void CallbackOpenDir(const char *pFileName, void *pUser) { if(str_comp(pEditor->m_aFileDialogPath, "maps") == 0 || str_comp(pEditor->m_aFileDialogPath, "mapres") == 0) return; - char aParentFolder[512]; - fs_parent_dir(pEditor->m_aFileDialogPath, aParentFolder); - str_copy(pEditor->m_aFileDialogPath, aParentFolder, sizeof(pEditor->m_aFileDialogPath)); + fs_parent_dir(pEditor->m_aFileDialogPath); } else str_copy(pEditor->m_aFileDialogPath, pFileName, sizeof(pEditor->m_aFileDialogPath)); + pEditor->m_aFileDialogFileName[0] = 0; pEditor->FilelistPopulate(); } @@ -604,6 +603,19 @@ static void CallbackOpenMap(const char *pFileName, void *pUser) static void CallbackAppendMap(const char *pFileName, void *pUser) { CEditor *pEditor = (CEditor*)pUser; + if(str_comp(pEditor->m_aFileDialogFileName, "..") == 0) + { + CallbackOpenDir("..", pUser); + return; + } + char aCompleteFilename[512]; + str_format(aCompleteFilename, sizeof(aCompleteFilename), "%s/%s", pEditor->Client()->UserDirectory(), pFileName); + if(fs_is_dir(aCompleteFilename)) + { + CallbackOpenDir(pFileName, pUser); + return; + } + if(pEditor->Append(pFileName)) pEditor->m_aFileName[0] = 0; else @@ -613,6 +625,20 @@ static void CallbackAppendMap(const char *pFileName, void *pUser) } static void CallbackSaveMap(const char *pFileName, void *pUser) { + CEditor *pEditor = static_cast(pUser); + if(str_comp(pEditor->m_aFileDialogFileName, "..") == 0) + { + CallbackOpenDir("..", pUser); + return; + } + char aCompleteFilename[512]; + str_format(aCompleteFilename, sizeof(aCompleteFilename), "%s/%s", pEditor->Client()->UserDirectory(), pFileName); + if(fs_is_dir(aCompleteFilename)) + { + CallbackOpenDir(pFileName, pUser); + return; + } + char aBuf[1024]; const int Length = str_length(pFileName); // add map extension @@ -622,7 +648,6 @@ static void CallbackSaveMap(const char *pFileName, void *pUser) pFileName = aBuf; } - CEditor *pEditor = static_cast(pUser); if(pEditor->Save(pFileName)) str_copy(pEditor->m_aFileName, pFileName, sizeof(pEditor->m_aFileName)); @@ -2123,6 +2148,9 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View) static void EditorListdirCallback(const char *pName, int IsDir, void *pUser) { + if(pName[0] == '.' && pName[1] == 0) + return; + CEditor *pEditor = (CEditor*)pUser; pEditor->m_FileList.add(string(pName)); } diff --git a/src/game/editor/ed_editor.h b/src/game/editor/ed_editor.h index f7d6d15f..30ec7203 100644 --- a/src/game/editor/ed_editor.h +++ b/src/game/editor/ed_editor.h @@ -460,9 +460,9 @@ public: m_aFileName[0] = 0; m_FileDialogDirTypes = 0; - m_pFileDialogTitle = NULL; - m_pFileDialogButtonText = NULL; - m_pFileDialogUser = NULL; + m_pFileDialogTitle = 0; + m_pFileDialogButtonText = 0; + m_pFileDialogUser = 0; m_aFileDialogFileName[0] = 0; m_aFileDialogPath[0] = 0; m_aFileDialogCompleteFilename[0] = 0; -- cgit 1.4.1