示例#1
0
        private static int RunPortableMode(CmdVerbPortableMode opts)
        {
            var container = CreateBuilder().Build();
            var rootScope = container.BeginLifetimeScope("recorder_root");
            var semaphore = new SemaphoreSlim(0, 1);
            var recorder  = rootScope.Resolve <IRecorder>();
            var config    = new ConfigV2()
            {
                DisableConfigSave = true,
            };

            if (!string.IsNullOrWhiteSpace(opts.Cookie))
            {
                config.Global.Cookie = opts.Cookie;
            }
            if (!string.IsNullOrWhiteSpace(opts.LiveApiHost))
            {
                config.Global.LiveApiHost = opts.LiveApiHost;
            }
            if (!string.IsNullOrWhiteSpace(opts.RecordFilenameFormat))
            {
                config.Global.RecordFilenameFormat = opts.RecordFilenameFormat;
            }

            config.Global.WorkDirectory = opts.OutputDirectory;
            config.Rooms = opts.RoomIds.Select(x => new RoomConfig {
                RoomId = x, AutoRecord = true
            }).ToList();

            ConsoleCancelEventHandler p = null !;

            p = (sender, e) =>
            {
                Console.CancelKeyPress -= p;
                e.Cancel = true;
                recorder.Dispose();
                semaphore.Release();
            };
            Console.CancelKeyPress += p;

            if (!((Recorder)recorder).InitializeWithConfig(config))
            {
                Console.WriteLine("Initialize Error");
                return(-1);
            }

            semaphore.Wait();
            return(0);
        }
示例#2
0
        public bool InitializeWithConfig(ConfigV2 config)
        {
            // 脏写法 but it works
            if (this._valid)
            {
                throw new InvalidOperationException("Recorder is in valid state");
            }

            if (config is null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            logger.Debug("Initialize With Config.");
            this.Config  = config;
            this.Webhook = new BasicWebhook(this.Config);
            this._valid  = true;
            this.Config.Rooms.ForEach(r => this.AddRoom(r));
            return(true);
        }
示例#3
0
 public BasicWebhook(ConfigV2 config)
 {
     this.Config = config ?? throw new ArgumentNullException(nameof(config));
 }
示例#4
0
        /// <summary> The actual Converter. It does compile the v2 config and copies over the Music and Icon File. You will have to edit line 58 (and maybe 61) manually, either by giving it some User Input by <see cref="System.Console.ReadLine()"/> or hardcoding it.
        /// </summary>
        public static void DecryptedMapBuilder()
        {
            DecryptedEvents decryptedEvents = GetDecryptedEvents();

            string localePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
            // Btw: You can also give a path like so: @"\Example\v3\config.txt"
            // Same end result. Only benefit could be some time savings.
                   encryptedConfigPath = localePath + "\\example\\v3\\config.txt",
                   configContent       = File.ReadAllText(encryptedConfigPath);

            ConfigV3     deserializedConfig = JsonConvert.DeserializeObject <ConfigV3>(configContent);
            ConfigV2     config             = new ConfigV2();
            List <Event> events             = new List <Event>();

            // We have to cheat a bit since Config 3 doesn't have those
            string        id                  = "editor.MyFriend";
            int           generationType      = 2;
            int           environmentType     = 3;
            List <object> puzzleSequencesList = new List <object>();

            // Set everything we can.
            config.id                  = id;
            config.name                = deserializedConfig.name;
            config.info                = deserializedConfig.info;
            config.levelResources      = deserializedConfig.levelResources;
            config.tags                = deserializedConfig.tags;
            config.handCount           = deserializedConfig.handCount;
            config.moreInfoURL         = deserializedConfig.moreInfoURL;
            config.speed               = deserializedConfig.speed;
            config.lives               = deserializedConfig.lives;
            config.maxLives            = deserializedConfig.maxLives;
            config.musicFile           = deserializedConfig.musicFile;
            config.musicTime           = deserializedConfig.musicTime;
            config.iconFile            = deserializedConfig.iconFile;
            config.generationType      = generationType;
            config.environmentType     = environmentType;
            config.unlockConditions    = deserializedConfig.unlockConditions;
            config.hidden              = deserializedConfig.hidden;
            config.checkpoints         = deserializedConfig.checkpoints;
            config.puzzleSequencesList = puzzleSequencesList;
            config.events              = decryptedEvents.events;

            // Create new Folder and copy over the Song and Icon, then write the config.
            string destinationPath = localePath + @"\example\v3-to-v2", destinationConfigPath = localePath + @"\example\v3-to-v2\config.txt";

            if (!Directory.Exists(destinationPath))
            {
                DirectoryInfo di = Directory.CreateDirectory(destinationPath);
            }

            string iconPath = localePath + @"\example\v3\icon.jpg", musicPath = localePath + @"\example\v3\music.ogg";

            if (!File.Exists(destinationPath + @"\icon.jpg"))
            {
                File.Copy(iconPath, destinationPath + @"\icon.jpg");
            }
            if (!File.Exists(destinationPath + @"\music.ogg"))
            {
                File.Copy(musicPath, destinationPath + @"\music.ogg");
            }
            File.WriteAllText(destinationConfigPath, Newtonsoft.Json.JsonConvert.SerializeObject(config));
        }