//ref http://www.dotnetperls.com/string-format
        //ref2: http://stackoverflow.com/questions/334630/open-folder-and-select-the-file
        private void ScanDemoFiles()
        {
            buttonRefresh.Enabled = false;
            listBoxDemoList.Items.Clear();

            //Process any new entry
            var demoFolder = Utils.MakePath(Program.SpringPaths.DataDirectories.First(), "demos");
            var demoFiles  = Directory.EnumerateFiles(demoFolder, "*.sdf");

            demoFiles = demoFiles.Reverse();

            foreach (var pathOfFiles in demoFiles)
            {
                var replayItem = new ReplayListItem();

                replayItem.filePath = pathOfFiles;
                replayItem.fileName = SkirmishControlTool.GetFolderOrFileName(pathOfFiles);

                InvokeIfNeeded(() =>
                {//crossthread calls
                    listBoxDemoList.Items.Add(replayItem);
                });
            }

            buttonRefresh.Enabled = true;
        }
Esempio n. 2
0
        /// <summary>
        /// Parse sides name from gamedata/sidedata.lua and side icon (.bmp format with same name as side name) from sidepics/
        /// </summary>
        public static void ReadSideInfo(string sidedataluaPath, string picPath, ref Mod modInfo)
        {
            if (!File.Exists(sidedataluaPath))
            {
                modInfo.Sides = new string[0];
                //modInfo.SideIcons = (new List<Byte[]>()).ToArray();
                //modInfo.StartUnits = new PlasmaShared.SerializableDictionary<string, string>(new Dictionary<string,string>());
                return;
            }

            using (FileStream fileStream = File.OpenRead(sidedataluaPath))
                using (var stream = new StreamReader(fileStream))
                {
                    var allText = stream.ReadToEnd();
                    int offset  = 0;
                    var config  = new TableReaderConfig();
                    var table   = TableReader.ParseTable(config, 0, allText, sidedataluaPath, out offset);

                    List <String> sides      = new List <String>();
                    List <byte[]> sideIcons  = new List <byte[]>();
                    var           startUnits = new Dictionary <string, string>(); //PlasmaShared.SerializableDictionary<string,string>();

                    foreach (var kvp in table)
                    {
                        String name      = "";
                        String startunit = "";
                        foreach (var kvp2 in (kvp.Value as Dictionary <String, Object>))
                        {
                            var value = (kvp2.Value as String);

                            switch (kvp2.Key)
                            {
                            case "name":
                                name = value;
                                break;

                            case "startunit":
                                startunit = value;
                                break;
                            }
                        }
                        if (name != "")
                        {
                            var picBytes = new Byte[0];
                            try{
                                var picList = Directory.EnumerateFiles(picPath);
                                using (FileStream fileStream2 = File.OpenRead(picList.First(x => SkirmishControlTool.GetFolderOrFileName(x).StartsWith(name, StringComparison.InvariantCultureIgnoreCase))))
                                {
                                    picBytes = new Byte[fileStream2.Length];
                                    fileStream2.Read(picBytes, 0, picBytes.Length);
                                }
                            }catch (Exception e) { System.Diagnostics.Trace.TraceError(e.ToString()); }
                            sides.Add(name);
                            sideIcons.Add(picBytes);
                            startUnits.Add(name, startunit);
                        }
                    }
                    modInfo.Sides      = sides.ToArray();
                    modInfo.SideIcons  = sideIcons.ToArray();
                    modInfo.StartUnits = new SerializableDictionary <string, string>(startUnits);
                }
        }