Jump to content

Get AppData Path


SpiderPig
 Share

Recommended Posts

Why not store this in program data? Are there really going to be multiple users on a computer your game is running, who each play the game and want to make sure their saves are stored separately?

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I stopped using it because it's not cross-platform, and it's really hard to navigate to. Program data is the intended replacement. I'm storing all the engine settings there.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 1 year later...

@Josh I'd like to revise this suggestion to be able to use GetPath() to get the APP_DATA_ROAMING path.

Looking at Steams cloud save system there is no option to have it navigate to the programdata path.  These are the available paths for cloud saving.  I would rather use the AppData path than the documents path.  Also might be an idea to have get the paths on Mac & Linux - when the time comes. ;)

SteamRootPaths.png.8431cba9ac231f1e0eee3793c66cbd17.png

 

Link to comment
Share on other sites

There are two Windows command that do this. With those you can get anything you want.

WCHAR szPath[MAX_PATH];
if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, szPath)))
{
	return WString(szPath).Replace("\\", "/");
}

PIDLIST_ABSOLUTE pidlist;
wchar_t path[MAX_PATH];
SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidlist);
SHGetPathFromIDListW(pidlist, path);
return WString(path).Replace("\\", "/");;

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

This is my code from my API where it grabs whatever system environment you want. I might look into implementing the above as old Win32 API code can cause AV's to get grumpy but I haven't had problems so far.
 

	const std::wstring System::GetSystemEnviormentW(const std::string& env)
	{
#ifdef _WIN32 
		wchar_t* buf = nullptr;
		size_t sz = 0;

		std::wstring wenv = String::ToWString(env);

		// Use _dupenv_s to get the environment variable
		if (_wdupenv_s(&buf, &sz, wenv.c_str()) == 0 && buf != nullptr)
		{
			std::wstring result(buf);
			free(buf); // Free the allocated buffer
			return result;
		}
#else
		auto s = std::getenv(env.c_str());
		if (s == NULL) return String::ToWString(s);
#endif
		return L""; // Environment variable not found or error occurred
	}

 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...