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
This commit is contained in:
parent
21408ee979
commit
77362e66f2
2 changed files with 106 additions and 1 deletions
|
@ -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
|
||||
|
|
105
src/misc/cross.cpp
Normal file
105
src/misc/cross.cpp
Normal file
|
@ -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 <string>
|
||||
|
||||
#ifdef WIN32
|
||||
#define _WIN32_IE 0x0400
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
#if defined HAVE_SYS_TYPES_H && defined HAVE_PWD_H
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#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
|
||||
}
|
Loading…
Add table
Reference in a new issue