garrysmod icon indicating copy to clipboard operation
garrysmod copied to clipboard

Add preset importing/exporting

Open peter-r-g opened this issue 4 years ago • 1 comments

This provides functionality to the addon preset system to have importing and exporting of presets. As far as I could tell all error cases have been caught and when they're caught a message gets put into the console. There is no form of visual feedback for when importing/exporting completes/fails outside of the console for errors.

Exporting

Exporting presets copies a string of characters to your clipboard that can then be taken elsewhere and imported. Information on the importing/exporting of data can be found below.

Importing

You can import presets in four different ways:

  1. From Export - This will read the data in assuming it is constructed from the export.
  2. JSON - This will read the data in as JSON (The format the data is saved in)
  3. URL - This will make a GET request to the URL provided and can be interpreted as either the "From Export" or "JSON" options.
  4. Collection ID(s) - This will read the data as a list of collections separated by a space (" ") character. The addon preset name will be defined by the collections provided. What this does is make POST requests to the Steam WebAPI (specifically https://api.steampowered.com/ISteamRemoteStorage/GetCollectionDetails/v1/) to get workshop items and collections inside of the original collection(s). Workshop items will be added and collections will be recursively added in later POST requests until all collections have been added.

Import/Export Base64 process (Credit to Spar for the idea):

Export: Lua preset table > util.TableToJSON > util.Compress > util.Base64Encode Import: util.Base64Decode > util.Decompress > util.JSONToTable > Lua preset table

New localization entries

This is more for the devs if this gets added, the following are the new strings that are added.

addons.export_preset - Text for the export button in the preset selection menu.
addons.import_preset - Text for the import preset button, title of the import preset menu, and text for the import preset button inside of the import preset menu.
addons.preset_import_method - Header text for selecting the import method in the import preset button.
addons.import_export - Text for importing from export radio button.
addons.import_json - Text for importing json radio button.
addons.import_url - Text for importing URL radio button.
addons.import_collection - Text for importing collection ID(s) radio button.
addons.preset_data_placeholder - Placeholder text for the data input textbox.

Console error meanings

Got invalid data, aborting preset import... - The data provided when "From Export" is selected is not in a valid form or no usable data is present.
Got invalid JSON data, aborting preset import... - The data provided when "JSON" is selected is not in a valid JSON format or is missing certain elements that are required.
Failed to retrieve addon preset for reason: *Insert Reason Here* - Some sort of HTTP error occurred when getting an addon preset from a URL.
URL preset import already in progress, aborting... - An HTTP request is already in progress for getting an addon preset.
Failed to retrieve addon collection for reason: *Insert Reason Here* - Some sort of HTTP error occurred when getting information on a collection.
Collection import already in progress, aborting... - An attempt at building a preset based on collections is already in progress.
Didn't get any collection IDs, aborting... - Filtering for invalid collection ID(s) returned no remaining items left.

Example Images

https://i.gyazo.com/f21d6c4ceae1a649c5951728d7966f69.png - Preset panel with export button https://i.gyazo.com/e02dac6a809eee631f578851df632bfd.png - New "Import Preset" button https://i.gyazo.com/d9e69190a91bc8456272c92dd27f3e6f.png - Import Preset menu

peter-r-g avatar Oct 20 '20 03:10 peter-r-g

In the future, when we get BitBuffers, I would change export/import to binary + base64, instead of json + LZMA + base64.

GitSparTV avatar Oct 20 '20 13:10 GitSparTV

I have implemented this suggestion myself.

https://github.com/Facepunch/garrysmod/commit/25204540c754ae503c7624fe5beccc6406248ba1

robotboy655 avatar Oct 06 '23 14:10 robotboy655