From 665934ee098abca1c7b585476502462b94b1bdc8 Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 8 Dec 2010 00:32:50 +0100 Subject: [PATCH] cleaned up several uses of timestamps for filenames --- src/engine/client/graphics.cpp | 22 ++---------- src/game/client/components/console.cpp | 38 ++++++++------------- src/game/client/components/menus_ingame.cpp | 10 +++--- 3 files changed, 20 insertions(+), 50 deletions(-) diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index 48988800e..fb9949533 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -29,7 +29,6 @@ #include #include -#include #include "graphics.h" @@ -883,28 +882,11 @@ void CGraphics_SDL::Swap() { if(m_DoScreenshot) { - // find filename char aFilename[128]; - static int Index = 1; - - time_t Time; char aDate[20]; - time(&Time); - tm* TimeInfo = localtime(&Time); - strftime(aDate, sizeof(aDate), "%Y-%m-%d_%I-%M", TimeInfo); - - for(; Index < 10000; Index++) - { - IOHANDLE io; - str_format(aFilename, sizeof(aFilename), "screenshots/screenshot%s-%05d.png", aDate, Index); - io = m_pStorage->OpenFile(aFilename, IOFLAG_READ, IStorage::TYPE_SAVE); - if(io) - io_close(io); - else - break; - } - + str_timestamp(aDate, sizeof(aDate)); + str_format(aFilename, sizeof(aFilename), "screenshots/screenshot_%s.png", aDate); ScreenshotDirect(aFilename); m_DoScreenshot = false; } diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 4d4219708..7688d7fb1 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -1,7 +1,6 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include -#include #include @@ -593,34 +592,25 @@ void CGameConsole::Dump(int Type) { CInstance *pConsole = Type == CONSOLETYPE_REMOTE ? &m_RemoteConsole : &m_LocalConsole; char aFilename[128]; - time_t Time; char aDate[20]; - time(&Time); - tm* TimeInfo = localtime(&Time); - strftime(aDate, sizeof(aDate), "%Y-%m-%d_%I-%M", TimeInfo); - - for(int i = 0; i < 10; i++) + str_timestamp(aDate, sizeof(aDate)); + str_format(aFilename, sizeof(aFilename), "dumps/%s_dump_%s.txt", Type==CONSOLETYPE_REMOTE?"remote_console":"local_console", aDate); + IOHANDLE io = Storage()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE); + if(io) { - IOHANDLE io; - str_format(aFilename, sizeof(aFilename), "dumps/%s_dump%s-%05d.txt", Type==CONSOLETYPE_REMOTE?"remote_console":"local_console", aDate, i); - io = Storage()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE); - if(io) - { - #if defined(CONF_FAMILY_WINDOWS) - static const char Newline[] = "\r\n"; - #else - static const char Newline[] = "\n"; - #endif + #if defined(CONF_FAMILY_WINDOWS) + static const char Newline[] = "\r\n"; + #else + static const char Newline[] = "\n"; + #endif - for(CInstance::CBacklogEntry *pEntry = pConsole->m_Backlog.First(); pEntry; pEntry = pConsole->m_Backlog.Next(pEntry)) - { - io_write(io, pEntry->m_aText, str_length(pEntry->m_aText)); - io_write(io, Newline, sizeof(Newline)-1); - } - io_close(io); - break; + for(CInstance::CBacklogEntry *pEntry = pConsole->m_Backlog.First(); pEntry; pEntry = pConsole->m_Backlog.Next(pEntry)) + { + io_write(io, pEntry->m_aText, str_length(pEntry->m_aText)); + io_write(io, Newline, sizeof(Newline)-1); } + io_close(io); } } diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index 75292249e..14a19f124 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -1,7 +1,5 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ -#include - #include #include @@ -103,10 +101,10 @@ void CMenus::RenderGame(CUIRect MainView) if(!Recording) { char aFilename[128]; - time_t Time; - time(&Time); - tm* TimeInfo = localtime(&Time); - strftime(aFilename, sizeof(aFilename), "demo-%Y-%m-%d_%H-%M-%S", TimeInfo); + char aDate[20]; + + str_timestamp(aDate, sizeof(aDate)); + str_format(aFilename, sizeof(aFilename), "demo_%s.png", aDate); Client()->DemoRecorder_Start(aFilename); } else