<commit_before>﻿using UnityEngine;
using UnityEditor;
using System.IO;

namespace SuperSystems.UnityBuild
{

public class UploadItch : BuildAction
{
    private const string WINDOWS = "windows";
    private const string OSX = "osx";
    private const string LINUX = "linux";

    #region MenuItems

    //[MenuItem("Build/Upload/itch.io/Execute", false, 50)]
    //private static void UploadAll()
    //{
        //for (int i = 0; i < BuildProject.platforms.Count; i++)
        //{
        //    BuildPlatform platform = BuildProject.platforms[i];
        //    PerformUpload(platform);
        //}
    //}

    //[MenuItem("Build/Upload/itch.io/Auto Upload")]
    //private static void ToggleAutoUpload()
    //{
    //    EditorPrefs.SetBool("buildUploadItchAuto", !EditorPrefs.GetBool("buildUploadItchAuto", false));
    //}

    //[MenuItem("Build/Upload/itch.io/Auto Upload", true)]
    //private static bool ToggleAutoUploadValidate()
    //{
    //    Menu.SetChecked("Build/Upload/itch.io/Auto Upload", EditorPrefs.GetBool("buildUploadItchAuto", false));
    //    return true;
    //}

    #endregion

    #region Public Methods

    //public override void Execute(BuildPlatform platform)
    //{
    //    if (EditorPrefs.GetBool("buildUploadItchAuto", false))
    //        PerformUpload(platform);
    //}

    #endregion

    #region Private Methods

    private static void PerformUpload(BuildPlatform platform)
    {
        //if (!platform.buildEnabled)
        //    return;

        //string absolutePath = Path.GetFullPath(platform.buildPath).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);

        //if (File.Exists(absolutePath))
        //{
        //    Debug.Log("UploadItch: Upload Failed - Build does not exist for platform " + platform.name + " - " + absolutePath);
        //    return;
        //}

        //string channel = GetChannelName(platform.target);
        //if (string.IsNullOrEmpty(channel))
        //{
        //    Debug.Log("UploadItch: Upload Failed - Unknown platform " + platform.name);
        //    return;
        //}

        //string arguments = "push \"" + absolutePath + "\" " + UploadItchSettings.itchUserName + "/" + UploadItchSettings.itchGameName + ":" + channel;

        //if (!string.IsNullOrEmpty(UploadItchSettings.versionNumber))
        //{
        //    arguments += "--userversion " + UploadItchSettings.versionNumber;
        //}

        //System.Diagnostics.Process uploadProc = new System.Diagnostics.Process();
        //uploadProc.StartInfo.FileName = UploadItchSettings.butlerPath;
        //uploadProc.StartInfo.Arguments =
        //    arguments;
        //uploadProc.StartInfo.CreateNoWindow = false;
        //uploadProc.StartInfo.UseShellExecute = false;
        //uploadProc.Start();
    }

    private static string GetChannelName(BuildTarget target)
    {
        switch (target)
        {
            // Windows
            case BuildTarget.StandaloneWindows:
                return WINDOWS + "-x86";
            case BuildTarget.StandaloneWindows64:
                return WINDOWS + "-x64";

            // Linux
            case BuildTarget.StandaloneLinux:
                return LINUX + "-x86";
            case BuildTarget.StandaloneLinux64:
                return LINUX + "-x64";
            case BuildTarget.StandaloneLinuxUniversal:
                return LINUX + "-universal";

            // OSX
            case BuildTarget.StandaloneOSXIntel:
                return OSX + "-intel";
            case BuildTarget.StandaloneOSXIntel64:
                return OSX + "-intel64";
            case BuildTarget.StandaloneOSXUniversal:
                return OSX + "-universal";
            
            default:
                return null;
        }
    }

    #endregion
}

}<commit_msg>Revived Itch module as a per-platform post-build action script. Requires the user to provide the file path to butler.exe and the user/game names of their Itch page<commit_after>﻿using UnityEngine;
using UnityEditor;
using System.IO;

namespace SuperSystems.UnityBuild
{

    public class UploadItch : BuildAction, IPostBuildAction, IPostBuildPerPlatformAction
    {
        [FilePath(false, true, "Path to butler.exe")]
        public string pathToButlerExe = "";
        public string nameOfItchUser = "";
        public string nameOfItchGame = "";
        [Header("The following field overrides the default channel name (the per-build architecture target), and will be applied to all builds. Use with care.")]
        public string itchChannelOverride = "";

        #region Public Methods

        public override void PerBuildExecute(BuildReleaseType releaseType, BuildPlatform platform, BuildArchitecture architecture, BuildDistribution distribution, System.DateTime buildTime, ref BuildOptions options, string configKey, string buildPath)
        {
            if (!File.Exists(pathToButlerExe))
            {
                UnityEngine.Debug.LogError("Couldn't find butler.exe file at path \"" + pathToButlerExe + "\", please check provided path");
                return;
            }
            string scriptArguments = "";
            if (!string.IsNullOrEmpty(itchChannelOverride))
            {
                scriptArguments = "push " + "\"" + buildPath + "\"" + " " + nameOfItchUser + "/" + nameOfItchGame + ":" + itchChannelOverride;
            }
            else
            {
                string itchChannel = GetChannelName(architecture.target);
                if(string.IsNullOrEmpty(itchChannel))
                {
                    UnityEngine.Debug.LogWarning("UploadItch: The current BuildTarget doesn't appear to be a standard Itch.IO build target.");
                }
                scriptArguments = "push " + "\"" + buildPath + "\"" + " " + nameOfItchUser + "/" + nameOfItchGame + ":" + GetChannelName(architecture.target);
            }

            //UnityEngine.Debug.Log("Would have run itch uploader with following command line: \"" + pathToButlerExe + " " + scriptArguments + "\"");
            RunScript(pathToButlerExe, scriptArguments);
        }

        #endregion

        #region Private Methods
        private const string WINDOWS = "windows";
        private const string OSX = "osx";
        private const string LINUX = "linux";

        private void RunScript(string scriptPath, string arguments)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = Path.GetFullPath(scriptPath);

            if (!string.IsNullOrEmpty(arguments))
                startInfo.Arguments = arguments;

            Process proc = Process.Start(startInfo);
            proc.WaitForExit();
        }

        private static string GetChannelName(BuildTarget target)
        {
            switch (target)
            {
                // Windows
                case BuildTarget.StandaloneWindows:
                    return WINDOWS + "-x86";
                case BuildTarget.StandaloneWindows64:
                    return WINDOWS + "-x64";

                // Linux
                case BuildTarget.StandaloneLinux:
                    return LINUX + "-x86";
                case BuildTarget.StandaloneLinux64:
                    return LINUX + "-x64";
                case BuildTarget.StandaloneLinuxUniversal:
                    return LINUX + "-universal";

                // OSX
                case BuildTarget.StandaloneOSXIntel:
                    return OSX + "-intel";
                case BuildTarget.StandaloneOSXIntel64:
                    return OSX + "-intel64";
                case BuildTarget.StandaloneOSXUniversal:
                    return OSX + "-universal";
            
                default:
                    return null;
            }
        }

        #endregion
    }

}
{'fraction_non_alphanumeric': 0.10242276631201128, 'fraction_numerical': 0.004486604281502372, 'mean_word_length': 1.9155455904334828, 'pattern_counts': {'":': 3, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '242740', 'n_tokens_mistral': 2097, 'n_tokens_neox': 1996, 'n_words': 459}