1 /************************************************************************
\r
3 ** Copyright (C) 2010 Strahinja Markovic
\r
5 ** This file is part of FlightCrew.
\r
7 ** FlightCrew is free software: you can redistribute it and/or modify
\r
8 ** it under the terms of the GNU Lesser General Public License as published
\r
9 ** by the Free Software Foundation, either version 3 of the License, or
\r
10 ** (at your option) any later version.
\r
12 ** FlightCrew is distributed in the hope that it will be useful,
\r
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 ** GNU Lesser General Public License for more details.
\r
17 ** You should have received a copy of the GNU Lesser General Public License
\r
18 ** along with FlightCrew. If not, see <http://www.gnu.org/licenses/>.
\r
20 *************************************************************************/
\r
23 #include "TempFolder.h"
\r
26 namespace FlightCrew
\r
29 static const char *UNIQUE_PATH_MODEL = "%%%%-%%%%-%%%%-%%%%-%%%%-%%%%-%%%%-%%%%";
\r
30 static const char *FC_TEMP_FOLDER = "flightcrew";
\r
32 TempFolder::TempFolder()
\r
33 : m_PathToFolder( GetNewTempFolderPath() )
\r
35 fs::create_directories( m_PathToFolder );
\r
39 TempFolder::~TempFolder()
\r
41 fs::remove_all( m_PathToFolder );
\r
45 fs::path TempFolder::GetPath()
\r
47 return m_PathToFolder;
\r
51 fs::path TempFolder::GetNewTempFolderPath()
\r
54 // The specified "c:\\temp" path will only be used
\r
55 // when the TMP environment variable is undefined
\r
56 // http://msdn.microsoft.com/en-us/library/hs3e7355.aspx
\r
57 wchar_t *tmp_name = _wtempnam( L"c:\\temp", L"unused" );
\r
58 fs::path main_temp_folder = fs::path( tmp_name ).parent_path();
\r
61 // GCC bitches and moans if we use tempnam(), so
\r
62 // we'll just use the P_tmpdir macro. We can't use
\r
63 // that on Win because it points to the drive root there
\r
64 // instead of the system temp folder
\r
65 // http://www.delorie.com/gnu/docs/glibc/libc_295.html
\r
66 fs::path main_temp_folder = fs::path( P_tmpdir );
\r
69 return main_temp_folder / fs::path( FC_TEMP_FOLDER ) / fs::unique_path( UNIQUE_PATH_MODEL );
\r
73 } // namespace FlightCrew
\r