system_path.cpp

来自「ncbi源码」· C++ 代码 · 共 268 行

CPP
268
字号
/* * =========================================================================== * PRODUCTION $Log: system_path.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 21:05:13  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4 * PRODUCTION * =========================================================================== *//*  $Id: system_path.cpp,v 1000.1 2004/06/01 21:05:13 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software / database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software / database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors:  Robert G. Smith * * File Description: *    CSystemPath -- System dependent functions needed by CGBenchApp, the main *                         application class for GBENCH */#include <ncbi_pch.hpp>#include <gui/utils/system_path.hpp>#include <corelib/ncbiapp.hpp>#include <corelib/ncbienv.hpp>#include <corelib/ncbifile.hpp>#include <gui/utils/message_box.hpp>#if defined(NCBI_OS_DARWIN)#define __NOEXTENSIONS__#include <Carbon/Carbon.h>#endifBEGIN_NCBI_SCOPE//// ResolvePath()// this function performs any standard app-specific directory mapping// so that we can use a series of standard aliases for directory names//string CSystemPath::ResolvePath(const string& path,                                const string& subdir){    string ret_val(path);    if (ret_val == "<std>") {        ret_val = GetStdPath();    } else if (ret_val == "<home>") {        ret_val = GetHomePath();    } else if (ret_val == "<res>") {        ret_val = GetResourcePath();    }    if ( !subdir.empty() ) {        ret_val += CDirEntry::GetPathSeparator();        ret_val += subdir;    }    return ret_val;}//// ResolvePathExisting ensures that a named file exists//string CSystemPath::ResolvePathExisting(const string& path,                                        const string& delim){    list<string> toks;    NStr::Split(path, delim, toks);    ITERATE( list<string>, iter, toks) {        string p(*iter);        p = NStr::TruncateSpaces(p);        string tmp = ResolvePath(p);        // check for existence        CDirEntry entry(tmp);        if (entry.Exists()) {            return tmp;        }    }    return string();}string CSystemPath::ResolvePath(const string& path){    string  path1, path2;    string  path_delim("\\/");    NStr::SplitInTwo(path, path_delim, path1, path2);    if ( ! path1.empty()) {        return ResolvePath(path1, path2);    }    return path;}// the GBench installation directory. Usually the parent of the App Path.// corresponds to the <std> alias in ResolvePath().string CSystemPath::GetStdPath(void){    string ret_val;    CNcbiApplication  *myApp = CNcbiApplication::Instance();    _ASSERT(myApp);    // First, was the value set in the environment variable $NCBI_GBENCH_HOME    ret_val = myApp->GetEnvironment().Get(string("NCBI_GBENCH_HOME"));    if (ret_val.empty()) {        // Next, look at the application's own location.        ret_val = myApp->GetArguments().GetProgramDirname();        if (!ret_val.empty()) {            // strip off the bin directory, if it is there.            string::size_type pos = ret_val.rfind("bin");            if (pos != string::npos  &&  pos == ret_val.length() - 4) {                ret_val.erase(pos);                while ( (pos = ret_val.find_last_of("\\/")) ==                         ret_val.length() - 1) {                    ret_val.erase(pos);                }            }        }        // Hmmm... We aren't where we should be.        if (ret_val.empty()) {            NcbiMessageBox("Warning:\n"                           "Can't identify the application's execution path.\n"                           "Some components may be unavailable.");        }    }        return ret_val;}string CSystemPath::GetResourcePath(){    string path = GetStdPath();    path += CDirEntry::GetPathSeparator();    path += "share";    return path;}// The place gbench keeps stuff.// corresponds to the <home> alias in ResolvePath().//   Is NOT the same as the user's home directory.//   That is returned by CDir::GetHome()string CSystemPath::GetHomePath(void){    string ret_val(CDir::GetHome());#if defined(NCBI_OS_UNIX)   &&  ! defined(NCBI_OS_DARWIN)    ret_val += ".gbench";#elif defined(NCBI_OS_DARWIN) // for now use the Unix location for Mac OS X.    OSErr       err;    short       appsuppVRefNum;    long        appsuppDirID;    FSSpec      appsuppFSSpec;    FSRef       appsuppFSRef;    char        appsuppPath[1024];    // Get the path to the Application Support folder for this user.    //     err = FindFolder(kUserDomain, kApplicationSupportFolderType, kCreateFolder,                      &appsuppVRefNum, &appsuppDirID);    if (err == noErr) {        err = FSMakeFSSpec(appsuppVRefNum, appsuppDirID,                           (ConstStr255Param) "", &appsuppFSSpec);        if (err == noErr  ||  err == fnfErr) {            err = FSpMakeFSRef(&appsuppFSSpec, &appsuppFSRef);            if (err == noErr) {                err = FSRefMakePath(&appsuppFSRef, (UInt8 *) appsuppPath, 1024);            }        }    }    if (err == noErr) {        ret_val = appsuppPath;            ret_val = CDirEntry::MakePath(ret_val, "gbench"); // not a hidden folder    } else {        // Problems getting the Mac Application Support folder?        // use ~/.gbench/ just like on other Unixes.        ret_val = CDirEntry::MakePath(ret_val, ".gbench");    }#elif defined(NCBI_OS_MSWIN)    ret_val += "GenomeWorkbench";#else#error "platform unrecognized"#endif    return ret_val;}END_NCBI_SCOPE/* * =========================================================================== * $Log: system_path.cpp,v $ * Revision 1000.1  2004/06/01 21:05:13  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4 * * Revision 1.4  2004/05/21 22:27:51  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.3  2004/05/20 12:41:30  dicuccio * Added standard resolution of '<res>' alias * * Revision 1.2  2004/05/07 17:54:11  dicuccio * Altered GetStdPath() - don't erase system path if it doesn't end in bin * * Revision 1.1  2004/02/17 20:35:20  rsmith * moved core/settings.[ch]pp and core/system_path.[ch]pp to config and utils, respectively. * * Revision 1.4  2004/01/21 12:36:07  dicuccio * Replace int with string::size_type where necessary * * Revision 1.3  2003/10/14 16:22:19  dicuccio * Added ResolvePathExisting().  Changed ResolvePath(const string&) to search all * delimited directories, not just the platform-specific one * * Revision 1.2  2003/08/25 17:57:12  rsmith * add member ResolvePath that splits and resolves a single string. * * Revision 1.1  2003/07/30 12:51:53  dicuccio * Moved 'gbench_system.[h,c]pp' to 'system_path.[h,c]pp' * * Revision 1.5  2003/07/30 12:18:48  dicuccio * Changed class name to CSystemPath.  Minor reformatting. * * Revision 1.4  2003/07/30 01:43:53  ucko * Fix path to gbench_system.hpp. * * Revision 1.3  2003/06/25 16:52:48  rsmith * <home> on Mac is in Users Application Support folder. * * Revision 1.2  2003/06/16 17:57:38  meric * Fixed to use string::erase() instead of string::clear() (MSVC++ peculiarity) * * Revision 1.1  2003/06/16 13:50:12  rsmith * initial checkin. Resolve paths in a system independent manner. * */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?