From 77362e66f24e1ca97098f90f3e7594f0aa909362 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Sun, 1 Feb 2009 14:16:52 +0000 Subject: [PATCH] Added cross.cpp, which has functions for the configuration file locations. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3282 --- src/misc/Makefile.am | 2 +- src/misc/cross.cpp | 105 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 src/misc/cross.cpp diff --git a/src/misc/Makefile.am b/src/misc/Makefile.am index 2cea9df3..968151af 100644 --- a/src/misc/Makefile.am +++ b/src/misc/Makefile.am @@ -1,4 +1,4 @@ AM_CPPFLAGS = -I$(top_srcdir)/include noinst_LIBRARIES = libmisc.a -libmisc_a_SOURCES = programs.cpp messages.cpp support.cpp setup.cpp +libmisc_a_SOURCES = cross.cpp messages.cpp programs.cpp setup.cpp support.cpp diff --git a/src/misc/cross.cpp b/src/misc/cross.cpp new file mode 100644 index 00000000..d444c993 --- /dev/null +++ b/src/misc/cross.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2002-2008 The DOSBox Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/* $Id: cross.cpp,v 1.1 2009-02-01 14:16:52 qbix79 Exp $ */ + +#include "dosbox.h" +#include "cross.h" +#include + +#ifdef WIN32 +#define _WIN32_IE 0x0400 +#include +#endif + +#if defined HAVE_SYS_TYPES_H && defined HAVE_PWD_H +#include +#include +#endif + + +void Cross::GetPlatformConfigDir(std::string& in) { +#ifdef WIN32 + char result[MAX_PATH] = { 0 }; + SHGetSpecialFolderPath(NULL,result,CSIDL_LOCAL_APPDATA,0); + in = result; + in += "\\DOSBox"; +#elif defined(MACOSX) + in = "/Library/Preferences"; + ResolveHomedir(in); +#else + in = "~/.dosbox"; + ResolveHomedir(in); +#endif + in += CROSS_FILESPLIT; +} + +void Cross::GetPlatformConfigName(std::string& in) { +#ifdef WIN32 +#define DEFAULT_CONFIG_FILE "dosbox-" VERSION ".conf" +#elif defined(MACOSX) +#define DEFAULT_CONFIG_FILE "DOSBox " VERSION " Preferences" +#else /*linux freebsd*/ +#define DEFAULT_CONFIG_FILE "dosbox-" VERSION ".conf" +#endif + in = DEFAULT_CONFIG_FILE; +} + +void Cross::CreatePlatformConfigDir(std::string& in) { +#ifdef WIN32 + char result[MAX_PATH] = { 0 }; + SHGetSpecialFolderPath(NULL,result,CSIDL_LOCAL_APPDATA,1); //1 at end is create + in = result; + in += "\\DOSBox"; + mkdir(in.c_str()); +#elif defined(MACOSX) + in = "~/Library/Preferences/"; + ResolveHomedir(in); + //Don't create it. Assume it exists +#else + in = "~/.dosbox"; + ResolveHomedir(in); + mkdir(in.c_str(),0700); +#endif + in += CROSS_FILESPLIT; +} + +void Cross::ResolveHomedir(std::string & temp_line) { + if(!temp_line.size() || temp_line[0] != '~') return; //No ~ + + if(temp_line.size() == 1 || temp_line[1] == CROSS_FILESPLIT) { //The ~ and ~/ variant + char * home = getenv("HOME"); + if(home) temp_line.replace(0,1,std::string(home)); +#if defined HAVE_SYS_TYPES_H && defined HAVE_PWD_H + } else { // The ~username variant + std::string::size_type namelen = temp_line.find(CROSS_FILESPLIT); + if(namelen == std::string::npos) namelen = temp_line.size(); + std::string username = temp_line.substr(1,namelen - 1); + struct passwd* pass = getpwnam(username.c_str()); + if(pass) temp_line.replace(0,namelen,pass->pw_dir); //namelen -1 +1(for the ~) +#endif // USERNAME lookup code + } +} + +void Cross::CreateDir(std::string const& in) { +#ifdef WIN32 + mkdir(in.c_str()); +#else + mkdir(in.c_str(),0700); +#endif +}