2020-12-05 13:08:24 +01:00
|
|
|
#include "user_account.h"
|
2020-02-15 23:36:20 +01:00
|
|
|
|
2021-04-21 22:12:21 +02:00
|
|
|
#include "Emu/system_utils.hpp"
|
2020-02-15 23:36:20 +01:00
|
|
|
#include "Utilities/File.h"
|
2020-03-07 10:29:23 +01:00
|
|
|
#include "util/logs.hpp"
|
2018-03-17 07:17:27 +01:00
|
|
|
|
2020-02-01 08:43:43 +01:00
|
|
|
LOG_CHANNEL(gui_log, "GUI");
|
2020-02-01 05:15:50 +01:00
|
|
|
|
2021-04-02 00:54:32 +02:00
|
|
|
user_account::user_account(const std::string& user_id)
|
2018-03-17 07:17:27 +01:00
|
|
|
{
|
|
|
|
|
// Setting userId.
|
2018-06-20 02:11:50 +02:00
|
|
|
m_user_id = user_id;
|
2018-03-17 07:17:27 +01:00
|
|
|
|
|
|
|
|
// Setting userDir.
|
2021-04-21 22:12:21 +02:00
|
|
|
m_user_dir = rpcs3::utils::get_hdd0_dir() + "home/" + m_user_id + "/";
|
2018-03-17 07:17:27 +01:00
|
|
|
|
|
|
|
|
// Setting userName.
|
2021-04-02 00:54:32 +02:00
|
|
|
if (fs::file file; file.open(m_user_dir + "localusername", fs::read))
|
2018-03-17 07:17:27 +01:00
|
|
|
{
|
2018-07-27 00:12:00 +02:00
|
|
|
m_username = file.to_string();
|
2018-03-17 07:17:27 +01:00
|
|
|
file.close();
|
2018-07-27 00:12:00 +02:00
|
|
|
|
|
|
|
|
if (m_username.length() > 16) // max of 16 chars on real PS3
|
|
|
|
|
{
|
|
|
|
|
m_username = m_username.substr(0, 16);
|
2021-04-02 00:54:32 +02:00
|
|
|
gui_log.warning("user_account: localusername of userId=%s was too long, cropped to: %s", m_user_id, m_username);
|
2018-07-27 00:12:00 +02:00
|
|
|
}
|
2018-03-17 07:17:27 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-02 00:54:32 +02:00
|
|
|
gui_log.error("user_account: localusername file read error (userId=%s, userDir=%s).", m_user_id, m_user_dir);
|
2018-03-17 07:17:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 00:54:32 +02:00
|
|
|
std::map<u32, user_account> user_account::GetUserAccounts(const std::string& base_dir)
|
|
|
|
|
{
|
|
|
|
|
std::map<u32, user_account> user_list;
|
|
|
|
|
|
|
|
|
|
// I believe this gets the folder list sorted alphabetically by default,
|
|
|
|
|
// but I can't find proof of this always being true.
|
|
|
|
|
for (const auto& user_folder : fs::dir(base_dir))
|
|
|
|
|
{
|
|
|
|
|
if (!user_folder.is_directory)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Is the folder name exactly 8 all-numerical characters long?
|
2021-04-21 22:12:21 +02:00
|
|
|
const u32 key = rpcs3::utils::check_user(user_folder.name);
|
2021-04-02 00:54:32 +02:00
|
|
|
|
|
|
|
|
if (key == 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Does the localusername file exist?
|
|
|
|
|
if (!fs::is_file(base_dir + "/" + user_folder.name + "/localusername"))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user_list.emplace(key, user_account(user_folder.name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return user_list;
|
|
|
|
|
}
|