Skip to content

How to Create a new Source

James Veugelaers edited this page Apr 5, 2025 · 4 revisions

A Source is a way for the Build Uploader to retrieve data so it can then be saved elsewhere and uploaded.

using System.Collections.Generic;
using System.Threading.Tasks;

namespace Wireframe
{
    internal class ExampleSource : ABuildSource
    {
        public ExampleSource(BuildUploaderWindow window) : base(window)
        {
        }

        public override string DisplayName { get; } // Name to be displayed in the drop
        public override void OnGUIExpanded(ref bool isDirty)
        {
            // User expanded the collapsed view to edit all the fields
        }

        public override void OnGUICollapsed(ref bool isDirty, float maxWidth)
        {
            // Shortened version of the GUI to be displayed on 1 line
        }

        public override Task<bool> GetSource(BuildConfig buildConfig)
        {
            // Add logic of downloading the build here
            // Use ProgressUtils to show progress
            // return true if retrieved successfully
            return Task.FromResult(true);
        }

        public override string SourceFilePath()
        {
            // The file path to the downloaded build
            return null;
        }

        public override float DownloadProgress()
        {
            // Return the progress of the download
            // 0.0f = 0% and 1.0f = 100%
            return m_downloadProgress;
        }

        public override string ProgressDescription()
        {
            // Return the description of the progress
            // eg: "Downloading from Steam"
            return m_progressDescription;
        }

        public override bool IsSetup(out string reason)
        {
            // Return true if the source is ready to be used
            // eg: A service is setup correctly
            // If not, return false and set the reason as to why eg: "MyService not setup"
            reason = "";
            return true;
        }

        public override string GetBuildDescription()
        {
            throw new System.NotImplementedException();
        }

        public override Dictionary<string, object> Serialize()
        {
            // Save the source data to a save
            return new Dictionary<string, object>
            {
                { "exampleKey", "exampleValue" }
            };
        }

        public override void Deserialize(Dictionary<string, object> data)
        {
            // Load the source data from a save
            if (data.TryGetValue("exampleKey", out var value))
            {
                // Do something with the value
            }
        }
    }
}

Clone this wiki locally