[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / platform / win10 / Environment.cpp
blob649a2993a74864c2774916247e758a7a95b64fb2
1 /*
2 * Copyright (C) 2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 /**
10 * \file platform\win10\Environment.cpp
11 * \brief Implements CEnvironment WinRT specified class functions.
14 #include "platform/Environment.h"
16 #include "platform/win32/CharsetConverter.h"
18 // --------------------- Internal Function ---------------------
20 /**
21 * \fn int CEnvironment::win_setenv(const std::wstring &name, const std::wstring &value = L"",
22 * updateAction action = autoDetect)
23 * \brief Internal function used to manipulate environment variables on WinRT.
25 * This function make all dirty work with setting, deleting and modifying environment variables.
27 * \param name The environment variable name.
28 * \param value (optional) the new value of environment variable.
29 * \param action (optional) the action.
30 * \return Zero on success and -1 otherwise
32 int CEnvironment::win_setenv(const std::string &name, const std::string &value /* = "" */, enum updateAction action /* = autoDetect */)
34 std::wstring Wname = KODI::PLATFORM::WINDOWS::ToW(name);
35 if (Wname.empty() || name.find('=') != std::wstring::npos)
36 return -1;
37 if ((action == addOnly || action == addOrUpdateOnly) && value.empty())
38 return -1;
39 if (action == addOnly && !getenv(name).empty())
40 return 0;
42 std::wstring Wvalue = KODI::PLATFORM::WINDOWS::ToW(value);
43 int retValue = 0;
45 // Update process Environment used for current process and for future new child processes
46 if (action == deleteVariable || value.empty())
47 retValue += SetEnvironmentVariableW(Wname.c_str(), nullptr) ? 0 : 4; // 4 if failed
48 else
49 retValue += SetEnvironmentVariableW(Wname.c_str(), Wvalue.c_str()) ? 0 : 4; // 4 if failed
51 return retValue;
54 std::string CEnvironment::win_getenv(const std::string &name)
56 if (name.empty())
57 return "";
59 uint32_t varSize = GetEnvironmentVariableA(name.c_str(), nullptr, 0);
60 if (varSize == 0)
61 return ""; // Not found
63 std::string result(varSize, 0);
64 GetEnvironmentVariableA(name.c_str(), const_cast<char*>(result.c_str()), varSize);
66 return result;