+ Added support for using background's ID so it's directly loaded from a steam installation directly (implements #101)

~ Updated readme with the new possibilities

Signed-off-by: Alexis Maiquez Murcia <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez Murcia 2022-06-01 22:54:25 +02:00
parent a12d05a61d
commit 46ea8e8f03
2 changed files with 104 additions and 56 deletions

View File

@ -29,8 +29,11 @@ In order to properly use this software you'll need to own an actual copy of the
The only way to get those assets is to install the Windows version through Steam. Luckily you don't really need a Windows installation for that. Using the Linux Steam client is enough to download the files we need. Note you may need to check "Enable Steam Play for all other titles" in the Steam Play section of Steam's settings if you haven't already. Also note that the software cannot actually be launched through Steam Play (Proton), but the setting is required for Steam to download the software.
## 5.2. Extracting needed assets
Once Wallpaper Engine is downloaded, open the installation folder (Right-Click the application in Steam -> Manage -> Browse local files). Here you'll see the main folders of Wallpaper Engine. The folder we're interested in is the one named "assets".
## 5.2. Extracting the assets
The automatic way doesn't require of anything extra, as long as Wallpaper Engine is installed in Steam the software should automatically detect where the assets are.
### 5.2.1. Extracting the assets manually
In the off-case where the software doesn't automatically detect the correct path, the assets can be extracted manually. Once Wallpaper Engine is downloaded, open the installation folder (Right-Click the application in Steam -> Manage -> Browse local files). Here you'll see the main folders of Wallpaper Engine. The folder we're interested in is the one named "assets".
![folder](docs/images/screenshot_folder.png)
@ -71,13 +74,28 @@ make
**REMEMBER: The assets folder has to be in the same folder as the executable**
## 5.5. Running a background
### 5.5.1. Getting the theme files
To get started, you need to "subscribe" to a theme, i.e. using the [example background](https://steamcommunity.com/sharedfiles/filedetails/?id=1845706469) click the +Subscribe button. Steam will automatically download the files for your subscriptions.
### 5.5.1. Running a background from Steam
Just like with the assets, the software can automatically detect where the subscribed backgrounds are stored. To get started, search in the workshop for whatever background you want to use and click the "+Subscribe" button. This should download the background in the steam directory.
You can find the files in the workshop directory located in your configured SteamLibrary directory (if you can't find it, just follow 5.2 and go up a couple directories). The actual files are located in `SteamLibrary/steamapps/workshop/content/431960/[workshop file ID]`. You can use these paths directly or copy over the files to a convenient location.
To actually use the background you'll need to know the workshop's ID. This can be obtained right-clicking anywhere in the background's page -> "Copy Page URL". You can paste this URL anywhere, it will look something like this:
```
https://steamcommunity.com/sharedfiles/filedetails/?id=1845706469&searchtext=portal+3
```
Where 1845706469 is the wallpaper's ID. You can use this ID to run wallengine:
```
./wallengine 1845706469
```
### 5.5.2. Running a background in a different folder
For the situations where the software cannot detect where the backgrounds are stored, you can specify a full path to it, like so:
```
./wallengine /home/almamu/Development/backgrounds/1845706469/
```
### 5.5.2. Running in a window (Default)
Currently both compressed and uncompressed backgrounds are supported. Loading them is quite simple. Just run linux-wallpaperengine with the path to the folder where the background is stored:
By default the app will load the backgrounds in a window so you can preview them:
```
./wallengine /home/almamu/Development/backgrounds/1845706469/
```

130
main.cpp
View File

@ -26,16 +26,26 @@ int g_AudioVolume = 15;
using namespace WallpaperEngine::Core::Types;
const char* default_paths[] = {
const char* assets_default_paths [] = {
".steam/steam/steamapps/common/wallpaper_engine/assets",
".local/share/Steam/steamapps/common/wallpaper_engine/assets",
nullptr
};
const char* backgrounds_default_paths [] = {
".local/share/Steam/steamapps/workshop/content/431960",
nullptr
};
void print_help (const char* route)
{
std::cout
<< "Usage:" << route << " [options] background_path" << std::endl
<< "Usage: " << route << " [options] background_path/background_id" << std::endl
<< std::endl
<< "where background_path/background_id can be:" << std::endl
<< "\tthe ID of the background (for autodetection on your steam installation)" << std::endl
<< "\ta full path to the background's folder" << std::endl
<< std::endl
<< "options:" << std::endl
<< " --silent\t\tMutes all the sound the wallpaper might produce" << std::endl
<< " --volume <amount>\tSets the volume for all the sounds in the background" << std::endl
@ -57,10 +67,6 @@ std::string stringPathFixes(const std::string& s)
.erase (str.size() - 1, 1)
.erase (0, 1);
// ensure there's a slash at the end of the path
if (str [str.size() - 1] != '/')
str += '/';
return std::move (str);
}
@ -91,6 +97,42 @@ int validatePath(const char* path, std::string& final)
return 0;
}
std::string getHomePath ()
{
char* home = getenv ("HOME");
if (home == nullptr)
throw std::runtime_error ("$HOME doesn't exist");
std::string homepath;
int error = validatePath (home, homepath);
if (error == ENOTDIR)
throw std::runtime_error ("Invalid user home path");
else if (error == ENAMETOOLONG)
throw std::runtime_error ("Cannot get user's home folder, path is too long");
else if (error != 0)
throw std::runtime_error ("Cannot find the home folder for the user");
return homepath;
}
void initGLFW ()
{
// first of all, initialize the window
if (glfwInit () == GLFW_FALSE)
throw std::runtime_error ("Failed to initialize GLFW");
// initialize freeimage
FreeImage_Initialise (TRUE);
// set some window hints (opengl version to be used)
glfwWindowHint (GLFW_SAMPLES, 4);
glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 1);
}
int main (int argc, char* argv[])
{
std::vector <std::string> screens;
@ -166,6 +208,32 @@ int main (int argc, char* argv[])
}
}
// attach signals so if a stop is requested the X11 resources are freed and the program shutsdown gracefully
std::signal(SIGINT, signalhandler);
std::signal(SIGTERM, signalhandler);
// initialize glfw
initGLFW ();
std::string homepath = getHomePath ();
auto containers = new WallpaperEngine::Assets::CCombinedContainer ();
// check if the background might be an ID and try to find the right path in the steam installation folder
if (path.find ('/') == std::string::npos)
{
for (const char** current = backgrounds_default_paths; *current != nullptr; current ++)
{
std::string tmppath = homepath + "/" + *current + "/" + path;
int error = validatePath (tmppath.c_str (), tmppath);
if (error != 0)
continue;
path = tmppath;
}
}
int error = validatePath (path.c_str (), path);
if (error == ENOTDIR)
@ -174,30 +242,8 @@ int main (int argc, char* argv[])
throw std::runtime_error ("Cannot get wallpaper's folder, path is too long");
else if (error != 0)
throw std::runtime_error ("Cannot find the specified folder");
// ensure the path has a trailing slash
// attach signals so if a stop is requested the X11 resources are freed and the program shutsdown gracefully
std::signal(SIGINT, signalhandler);
std::signal(SIGTERM, signalhandler);
// first of all, initialize the window
if (glfwInit () == GLFW_FALSE)
{
fprintf (stderr, "Failed to initialize GLFW\n");
return 1;
}
// initialize freeimage
FreeImage_Initialise (TRUE);
// set some window hints (opengl version to be used)
glfwWindowHint (GLFW_SAMPLES, 4);
glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 1);
auto containers = new WallpaperEngine::Assets::CCombinedContainer ();
// update the used path with the full one
// add a trailing slash to the path so the right file can be found
path += "/";
// the background's path is required to load project.json regardless of the type of background we're using
@ -211,12 +257,12 @@ int main (int argc, char* argv[])
containers->add (new WallpaperEngine::Assets::CPackage (scene_path));
std::cout << "Detected scene.pkg file at " << scene_path << ". Adding to list of searchable paths" << std::endl;
}
catch (CPackageLoadException ex)
catch (CPackageLoadException& ex)
{
// ignore this error, the package file was not found
std::cout << "No scene.pkg file found at " << path << ". Defaulting to normal folder storage" << std::endl;
}
catch (std::runtime_error ex)
catch (std::runtime_error& ex)
{
// the package was found but there was an error loading it (wrong header or something)
fprintf (stderr, "Failed to load scene.pkg file: %s\n", ex.what());
@ -225,23 +271,7 @@ int main (int argc, char* argv[])
if (assetsDir.empty () == true)
{
char* home = getenv ("HOME");
if (home == nullptr)
throw std::runtime_error ("$HOME doesn't exist");
std::string homepath;
error = validatePath (home, homepath);
if (error == ENOTDIR)
throw std::runtime_error ("Invalid user home path");
else if (error == ENAMETOOLONG)
throw std::runtime_error ("Cannot get user's home folder, path is too long");
else if (error != 0)
throw std::runtime_error ("Cannot find the home folder for the user");
for (const char** current = default_paths; *current != nullptr; current ++)
for (const char** current = assets_default_paths; *current != nullptr; current ++)
{
std::string tmppath = homepath + "/" + *current;
@ -262,7 +292,7 @@ int main (int argc, char* argv[])
strncpy (copy, argv [0], len);
// path still not found, try one last thing on the current binarie's folder
// path still not found, try one last thing on the current binary's folder
std::string exepath = dirname (copy);
exepath += "/assets";
@ -291,7 +321,7 @@ int main (int argc, char* argv[])
std::cout << "Found wallpaper engine's assets at " << assetsDir << " based on --assets-dir parameter" << std::endl;
}
if (assetsDir == "")
if (assetsDir.empty () == true)
throw std::runtime_error ("Cannot determine a valid path for the wallpaper engine assets");
// add containers to the list