Пример #1
0
// static
bool OTPaths::GetHomeFromSystem(String& out_strHomeFolder)
{
#ifdef _WIN32
#ifdef _UNICODE
    TCHAR szPath[MAX_PATH] = L"";
#else
    TCHAR szPath[MAX_PATH] = "";
#endif

    if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
                                  nullptr, 0, szPath))) {
#ifdef UNICODE
        out_strHomeFolder.Set(utf8util::UTF8FromUTF16(szPath));
#else
        out_strHomeFolder.Set(szPath);
#endif
    }
    else {
        out_strHomeFolder.Set("");
        return false;
    }

#elif defined(__APPLE__)

    String home(getenv("HOME"));
    String library = "";
    AppendFolder(library, home, "Library");
    AppendFolder(out_strHomeFolder, library, "Application Support");

#else
    out_strHomeFolder.Set(getenv("HOME"));
#endif

    return out_strHomeFolder.Exists();
}
Пример #2
0
const OTString & OTPaths::AppDataFolder()
{
	if (m_strAppDataFolder.Exists()) return m_strAppDataFolder;  // already got it, just return it.

	OTString strHomeDataFolder(""), strAppDataFolder("");  // eg. /home/user/  (the folder that the OT appdata folder will be in.)

	if(!GetHomeFromSystem(strHomeDataFolder)) { OT_ASSERT(false); return m_strAppDataFolder; }

	// now lets change all the '\' into '/'
	// then check that the path /home/user indeed exists, and is a folder.

	FixPath(strHomeDataFolder,strHomeDataFolder,true);
	if(!PathExists(strHomeDataFolder)) OT_ASSERT(false);

	// ok, we have the HomeData Folder, lets append our OT folder to it.

	if(!AppendFolder(strAppDataFolder,strHomeDataFolder,OT_APPDATA_DIR)) OT_ASSERT(false);

	bool bFolderCreated;
	if(!BuildFolderPath(strAppDataFolder,bFolderCreated)) OT_ASSERT(false);

	m_strAppDataFolder = strAppDataFolder;  // all good lets set it.

	return m_strAppDataFolder;
}
Пример #3
0
void CFolderHelper::CreateNewFolder(TElTree* tv, bool bEditAfterCreate)
{
	AnsiString folder;
    AnsiString start_folder;
    MakeName(tv->Selected,0,start_folder,true);
    TElTreeItem* parent = tv->Selected?(IsFolder(tv->Selected)?tv->Selected:tv->Selected->Parent):0;
    GenerateFolderName(tv,parent,folder);
    folder = start_folder+folder;
	TElTreeItem* node = AppendFolder(tv,folder.c_str(),true);
    if (tv->Selected) tv->Selected->Expand(false);
    if (bEditAfterCreate) tv->EditItem(node,-1);
}
Пример #4
0
CFMutableArrayRef AppendItem(struct SpringboardDeviceInfo *info, CFPropertyListRef homescreen, CFMutableArrayRef screen, CFDictionaryRef item) {
	uint8_t type = ResolveSpringboardItemType(item);
	switch (type) {
		case SpringboardIconTypeInvalid: {
			printf("This item is of an unknown type, skipping...\n");
			break;
		};
		case SpringboardIconTypeApp: {
			screen = AppendApp(info, homescreen, screen, item);
			break;
		};
		case SpringboardIconTypeFolder: {
			screen = AppendFolder(info, homescreen, screen, item);
			break;
		};
		default: {
			break;
		};
	}
	return screen;
}
Пример #5
0
const bool OTPaths::LoadSetScriptsFolder  // ie. PrefixFolder() + lib/opentxs/
	(
	OTSettings * pConfig, //optional
	const OTString & strScriptsFolder,	//optional
	const bool & bIsRelative			//optional
	)
{
	if (NULL == pConfig)  { OT_ASSERT(false); return false; }

	const bool bPreLoaded(pConfig->IsLoaded());

	if (!bPreLoaded)
	{
		pConfig->Reset();
		if(!pConfig->Load()) { OT_ASSERT(false); return false; }
	}

	OTString strRelativeKey = "";
	strRelativeKey.Format("%s%s","scripts",OT_CONFIG_ISRELATIVE);

	// local vairables.
	bool bConfigIsRelative = false;
	OTString strConfigFolder = "";

	bool bKeyIsNew = false;

	if (!pConfig->CheckSet_bool("paths",strRelativeKey,true,bConfigIsRelative,bKeyIsNew)) { return false; }
	if (!pConfig->CheckSet_str("paths","scripts",OT_SCRIPTS_DIR,strConfigFolder,bKeyIsNew)) { return false; }

	if (!strConfigFolder.Compare(strScriptsFolder))  // only if we need to.
	{
		if(strScriptsFolder.Exists() && (3 < strScriptsFolder.GetLength()))
		{
			// update the local vairables.
			bConfigIsRelative = bIsRelative;
			strConfigFolder = strScriptsFolder;

			bool bNewOrUpdated = false;

			if (!pConfig->Set_bool("paths","scripts_is_",bConfigIsRelative,bNewOrUpdated)) { return false; }
			if (!pConfig->Set_str( "paths","scripts",strConfigFolder,bNewOrUpdated)) {return false; }
		}
	}

	if(bIsRelative)
	{
		if(!FixPath(strConfigFolder,strConfigFolder,true)) { OT_ASSERT(false); return false; }

		OTString strScriptPath = "";
		if(AppendFolder(strScriptPath,PrefixFolder(),strConfigFolder)); else { OT_ASSERT(false); return false; }

		m_strScriptsFolder = strScriptPath; // set
	}
	else
	{
		if(!ToReal(strConfigFolder,strConfigFolder)) { OT_ASSERT(false); return false; }
		if(!FixPath(strConfigFolder,strConfigFolder,true)) { OT_ASSERT(false); return false; }
		m_strScriptsFolder = strConfigFolder; // set
	}

	if (!bPreLoaded)
	{
		if(!pConfig->Save()) { OT_ASSERT(false); return false; }
		pConfig->Reset();
	}
	return true;  // success
}
Пример #6
0
// static
bool OTPaths::LoadSetScriptsFolder   // ie. PrefixFolder() + [ if (NOT Android)
                                     // "lib/opentxs/" ]
    (OTSettings& config,             // optional
     const String& strScriptsFolder, // optional
     const bool& bIsRelative         // optional
     )
{
    if (&config == &s_settings) ConfigureDefaultSettings();

    const bool bPreLoaded(config.IsLoaded());

    if (!bPreLoaded) {
        config.Reset();
        if (!config.Load()) {
            OT_FAIL;
        }
    }

    String strRelativeKey = "";
    strRelativeKey.Format("%s%s", "scripts", OT_CONFIG_ISRELATIVE);

    // local vairables.
    bool bConfigIsRelative = false;
    String strConfigFolder = "";

    // lets first check what we have in the configuration:
    {
        bool bKeyIsNew = false;

        if (!config.CheckSet_bool("paths", strRelativeKey, true,
                                  bConfigIsRelative, bKeyIsNew)) {
            return false;
        }
        if (!config.CheckSet_str("paths", "scripts", OT_SCRIPTS_DIR,
                                 strConfigFolder, bKeyIsNew)) {
            return false;
        }
    }

    // lets first test if there was a folder passed in

    if ((strScriptsFolder.Exists()) && (3 < strScriptsFolder.GetLength())) {

        // we have a folder passed in, lets now check if we need to update
        // anything:

        if (bConfigIsRelative != bIsRelative) {

            bConfigIsRelative = bIsRelative;
            bool bNewOrUpdated = false;

            if (!config.Set_bool("paths", strRelativeKey, bConfigIsRelative,
                                 bNewOrUpdated)) {
                return false;
            }
        }

        if (!strConfigFolder.Compare(strScriptsFolder)) {

            strConfigFolder = strScriptsFolder; // update folder
            bool bNewOrUpdated = false;

            if (!config.Set_str("paths", "scripts", strConfigFolder,
                                bNewOrUpdated)) {
                return false;
            }
        }
    }

    if (bConfigIsRelative) {
        if (!FixPath(strConfigFolder, strConfigFolder, true)) {
            OT_FAIL;
        }

        String strPrefixScriptPath = "";
        AppendFolder(strPrefixScriptPath, PrefixFolder(), strConfigFolder);

        String strAppBinaryScriptPath = "";

        // if the AppBinaryFolder is set, we will attempt to use this script
        // path instead.
        // however if the directory dosn't exist, we will default back to
        // appending to the prefix.

        // TODO:  Make the prefix path set to AppBinaryFolder. (da2ce7)

        if (AppBinaryFolder().Exists()) {
            AppendFolder(strAppBinaryScriptPath, AppBinaryFolder(),
                         strConfigFolder);
            if (!OTPaths::FolderExists(strAppBinaryScriptPath)) {
                otOut << __FUNCTION__
                      << ": Warning: Cannot Find: " << strAppBinaryScriptPath
                      << ", using default!";
                strAppBinaryScriptPath = ""; // don't have anything here.
            }
        }

        s_strScriptsFolder = strAppBinaryScriptPath.Exists()
                                 ? strAppBinaryScriptPath
                                 : strPrefixScriptPath;

        if (!s_strScriptsFolder.Exists()) OT_FAIL;

    }
    else {
        if (!ToReal(strConfigFolder, strConfigFolder)) {
            OT_FAIL;
        }

        if (!FixPath(strConfigFolder, strConfigFolder, true)) {
            OT_FAIL;
        }
        s_strScriptsFolder = strConfigFolder; // set
    }

    if (!bPreLoaded) {
        if (!config.Save()) {
            OT_FAIL;
        }
        config.Reset();
    }
    return true; // success
}
Пример #7
0
const bool OTPaths::LoadSetScriptsFolder  // ie. PrefixFolder() + lib/opentxs/
	(
	OTSettings * pConfig, //optional
	const OTString & strScriptsFolder,	//optional
	const bool & bIsRelative			//optional
	)
{
	if (NULL == pConfig)  { OT_ASSERT(false); return false; }

	const bool bPreLoaded(pConfig->IsLoaded());

	if (!bPreLoaded)
	{
		pConfig->Reset();
		if(!pConfig->Load()) { OT_ASSERT(false); return false; }
	}

	OTString strRelativeKey = "";
	strRelativeKey.Format("%s%s","scripts",OT_CONFIG_ISRELATIVE);


	// local vairables.
	bool bConfigIsRelative = false;
	OTString strConfigFolder = "";


	// lets first check what we have in the configuration:
	{
	bool bKeyIsNew = false;

	if (!pConfig->CheckSet_bool("paths",strRelativeKey,true,bConfigIsRelative,bKeyIsNew)) { return false; }
	if (!pConfig->CheckSet_str("paths","scripts",OT_SCRIPTS_DIR,strConfigFolder,bKeyIsNew)) { return false; }
	}

	// lets first test if there was a folder passed in

	if ((strScriptsFolder.Exists()) && (3 < strScriptsFolder.GetLength())) {

		// we have a folder passed in, lets now check if we need to update anything:

		if (bConfigIsRelative != bIsRelative) {

			bConfigIsRelative = bIsRelative;
			bool bNewOrUpdated = false;

			if (!pConfig->Set_bool("paths", strRelativeKey, bConfigIsRelative, bNewOrUpdated)) { return false; }

		}

		if (!strConfigFolder.Compare(strScriptsFolder)) {

			strConfigFolder = strScriptsFolder; // update folder
			bool bNewOrUpdated = false;

			if (!pConfig->Set_str( "paths", "scripts", strConfigFolder, bNewOrUpdated)) { return false; }
		}
	}


	if(bConfigIsRelative)
	{
		if(!FixPath(strConfigFolder,strConfigFolder,true)) { OT_ASSERT(false); return false; }

		OTString strScriptPath = "";
		if(!AppendFolder(strScriptPath, PrefixFolder(), strConfigFolder)) { OT_ASSERT(false); return false; }

		m_strScriptsFolder = strScriptPath; // set
	}
	else
	{
		if(!ToReal(strConfigFolder, strConfigFolder)) { OT_ASSERT(false); return false; }
		if(!FixPath(strConfigFolder, strConfigFolder, true)) { OT_ASSERT(false); return false; }
		m_strScriptsFolder = strConfigFolder; // set
	}
		
	if (!bPreLoaded)
	{
		if(!pConfig->Save()) { OT_ASSERT(false); return false; }
		pConfig->Reset();
	}
	return true;  // success
}