Skip to content

Commit

Permalink
fastdl progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Joelrau committed Aug 6, 2024
1 parent 75be9b1 commit 116b747
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 69 deletions.
40 changes: 40 additions & 0 deletions data/cdata/ui_scripts/Mods/ModDownload.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function ModDownloadCancel( arg0, arg1 )
download.abort()
LUI.FlowManager.RequestLeaveMenu( arg0 )
end

function ModDownloadPopup( arg0, arg1 )
local popup = MenuBuilder.BuildRegisteredType( "FenceDialogPopup", {
message = "Downloading files...",
controllerIndex = arg1.controllerIndex,
onCancel = ModDownloadCancel
} )
popup.id = "ModDownloadPopup"

local file = ""

popup:registerEventHandler("mod_download_set_file", function(element, event)
file = event.request.name
popup.Message:setText(string.format("Downloading %s...", file))
end)

popup:registerEventHandler("mod_download_progress", function(element, event)
popup.Message:setText(string.format("Downloading %s (%i%%)...", file, math.floor(event.fraction * 100)))
end)

popup:registerEventHandler("mod_download_done", function()
LUI.FlowManager.RequestLeaveMenu(popup)
end)

return popup
end

MenuBuilder.registerType( "ModDownloadPopup", ModDownloadPopup )

local function reg_func()
Engine.GetLuiRoot():registerEventHandler("mod_download_start", function(element, event)
LUI.FlowManager.RequestPopupMenu( element, "ModDownloadPopup", true, event.controller, false )
end)
end

scheduler.once(reg_func)
2 changes: 1 addition & 1 deletion data/cdata/ui_scripts/Mods/__init__.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ require( "ModSelectButton" )
require( "ModSelectMenu" )

if (Engine.InFrontend()) then
--require("download")
require("ModDownload")
end
7 changes: 2 additions & 5 deletions src/client/component/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace download
}, scheduler::pipeline::lui);
}

//console::debug("Download progress: %lli/%lli\n", progress, total);
console::debug("Download progress: %lli/%lli\n", progress, total);
if (download_aborted())
{
return -1;
Expand All @@ -99,10 +99,7 @@ namespace download

void menu_error(const std::string& error)
{
scheduler::once([=]
{
game::shared::menu_error(error);
}, scheduler::pipeline::lui);
throw std::runtime_error(error);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/client/component/party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ namespace party
}
catch (const std::exception& e)
{
command::execute("luiLeaveMenu AcceptingInvite", true);
game::shared::menu_error(e.what());
return true;
}
Expand Down Expand Up @@ -399,6 +400,13 @@ namespace party
{
profile_infos::xuid::clear_xuids();

hash_cache.clear();

if (game::environment::is_dedi())
{
generate_hashes(map);
}

preloaded_map = map_is_preloaded;
sv_start_map_for_party_hook.invoke<void>(map, game_type, client_count, agent_count, hardcore, map_is_preloaded, migrate);
}
Expand Down Expand Up @@ -851,7 +859,7 @@ namespace party
info.set("sv_discordImageUrl", get_dvar_string("sv_discordImageUrl"));
info.set("sv_discordImageText", get_dvar_string("sv_discordImageText"));

/*const auto fs_game = get_dvar_string("fs_game");
const auto fs_game = get_dvar_string("fs_game");
info.set("fs_game", fs_game);

if (!fs_game.empty())
Expand All @@ -862,7 +870,7 @@ namespace party
fs_game.data(), file.extension.data()));
info.set(file.name, hash);
}
}*/
}

network::send(target, "infoResponse", info.build(), '\n');
});
Expand Down
2 changes: 0 additions & 2 deletions src/client/component/scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ namespace scripting
std::unordered_map<std::string, std::vector<std::pair<std::string, const char*>>> script_function_table_sort;
std::unordered_map<const char*, std::pair<std::string, std::string>> script_function_table_rev;

utils::concurrency::container<shared_table_t> shared_table;

std::string current_file;

namespace
Expand Down
4 changes: 0 additions & 4 deletions src/client/component/scripting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@

namespace scripting
{
using shared_table_t = std::unordered_map<std::string, std::string>;

extern std::unordered_map<int, std::unordered_map<std::string, int>> fields_table;
extern std::unordered_map<std::string, std::unordered_map<std::string, const char*>> script_function_table;
extern std::unordered_map<std::string, std::vector<std::pair<std::string, const char*>>> script_function_table_sort;
extern std::unordered_map<const char*, std::pair<std::string, std::string>> script_function_table_rev;

extern utils::concurrency::container<shared_table_t> shared_table;

extern std::string current_file;

void on_shutdown(const std::function<void(bool, bool)>& callback);
Expand Down
80 changes: 25 additions & 55 deletions src/client/component/ui_scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "game/game.hpp"
#include "game/dvars.hpp"


#include "command.hpp"
#include "console/console.hpp"
#include "fastfiles.hpp"
Expand All @@ -15,6 +14,7 @@
#include "scheduler.hpp"
#include "scripting.hpp"
#include "server_list.hpp"
#include "download.hpp"

#include "game/ui_scripting/execution.hpp"
//#include "game/scripting/execution.hpp"
Expand Down Expand Up @@ -183,60 +183,6 @@ namespace ui_scripting
};
*/

game_type["sharedset"] = [](const game&, const std::string& key, const std::string& value)
{
scripting::shared_table.access([key, value](scripting::shared_table_t& table)
{
table[key] = value;
});
};

game_type["sharedget"] = [](const game&, const std::string& key)
{
std::string result;
scripting::shared_table.access([key, &result](scripting::shared_table_t& table)
{
result = table[key];
});
return result;
};

game_type["sharedclear"] = [](const game&)
{
scripting::shared_table.access([](scripting::shared_table_t& table)
{
table.clear();
});
};

/*
game_type["assetlist"] = [](const game&, const std::string& type_string)
{
auto table_ = table();
auto index = 1;
auto type_index = -1;
for (auto i = 0; i < ::game::XAssetType::ASSET_TYPE_COUNT; i++)
{
if (type_string == ::game::g_assetNames[i])
{
type_index = i;
}
}
if (type_index == -1)
{
throw std::runtime_error("Asset type does not exist");
}
const auto type = static_cast<::game::XAssetType>(type_index);
fastfiles::enum_assets(type, [type, &table_, &index](const ::game::XAssetHeader header)
{
const auto asset = ::game::XAsset{type, header};
const std::string asset_name = ::game::DB_GetXAssetName(&asset);
table_[index++] = asset_name;
}, true);
return table_;
};
*/

game_type["getcurrentgamelanguage"] = [](const game&)
{
return steam::SteamApps()->GetCurrentGameLanguage();
Expand All @@ -248,11 +194,35 @@ namespace ui_scripting
material.data()));
};

auto scheduler = table();
lua["scheduler"] = scheduler;

scheduler["once"] = [](const function_argument& args)
{
scheduler::once([args]()
{
auto func = args.as<function>();
func();
}, scheduler::lui);
};

auto server_list_table = table();
lua["serverlist"] = server_list_table;

server_list_table["getplayercount"] = server_list::get_player_count;
server_list_table["getservercount"] = server_list::get_server_count;

auto download_table = table();
lua["download"] = download_table;

download_table["abort"] = download::stop_download;

//download_table["userdownloadresponse"] = party::user_download_response;
//download_table["getwwwurl"] = []
//{
// const auto state = party::get_server_connection_state();
// return state.base_url;
//};
}

void enable_globals()
Expand Down

0 comments on commit 116b747

Please sign in to comment.