Exemplo n.º 1
0
        public void FlushINI()
        {
            var ini = new StrangeIni();
            var top = ini.topSection;

            top["view"]   = lvApps.View.ToString();
            top["width"]  = "" + Width;
            top["height"] = "" + Height;
            //

            foreach (var pair in lvApps.GetSortedItems())
            {
                var item = pair.Value;
                var sct  = ini.AddSection("Bookmark");
                sct["path"] = item.FullPath;
                sct["name"] = item.Text;
                sct["text"] = item.Notes;
                sct["icon"] = item.IconPath;
                sct["args"] = item.CLIArgs;
                if (item.ForceWindowed)
                {
                    sct["fwnd"] = "1";
                }
            }
            //
            var unsavedData = ini.Save(IniPath);

            if (unsavedData != null)
            {
                if (MessageBox.Show(
                        "Failed to save bookmarks! Would you like INI text to be copied to your clipboard?",
                        Text, MessageBoxButtons.YesNo, MessageBoxIcon.Error
                        ) == DialogResult.Yes)
                {
                    Clipboard.SetText(unsavedData);
                }
            }
        }
Exemplo n.º 2
0
        public FormMain()
        {
            InitializeComponent();
            Icon = Properties.Resources.GMT;
            typeof(Control).GetProperty("DoubleBuffered",
                                        System.Reflection.BindingFlags.NonPublic |
                                        System.Reflection.BindingFlags.Instance)
            .SetValue(lvApps, true, null);
            //
            var AppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            var AppDir  = AppData + @"\GMTogether";

            if (!Directory.Exists(AppDir))
            {
                try {
                    Directory.CreateDirectory(AppDir);
                } catch (Exception e) {
                    MessageBox.Show("Failed to create an appdata directory!"
                                    + " Very cursed."
                                    + " This means that we won't be able to save your bookmarks."
                                    + " See if you are missing user permissions somehow."
                                    + " Full error:\r\n" + e,
                                    Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            IniPath = AppDir + @"\GMTUI.ini";
            //
            ExeFolder    = Path.GetDirectoryName(Application.ExecutablePath);
            LauncherPath = ExeFolder + @"\GMT-Launcher.exe";
            if (!File.Exists(LauncherPath))
            {
                MessageBox.Show(
                    "Please extract GMT to GMTUI's directory before using the program.",
                    Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            //
            var ini = new StrangeIni();

            if (ini.Load(IniPath))
            {
                var top = ini.topSection;
                try {
                    lvApps.View = (View)Enum.Parse(typeof(View), top["view"]);
                    switch (lvApps.View)
                    {
                    case View.Details:
                        SyncViewItems(tsiViewDetails);
                        break;

                    case View.LargeIcon:
                        SyncViewItems(tsiViewBigIcons);
                        break;

                    case View.SmallIcon:
                        SyncViewItems(tsiViewSmallIcons);
                        break;

                    case View.List:
                        SyncViewItems(tsiViewList);
                        break;

                    case View.Tile:
                        SyncViewItems(tsiViewTile);
                        break;
                    }
                } catch (Exception) { }
                if (int.TryParse(top["width"], out var w))
                {
                    Width = w;
                }
                if (int.TryParse(top["height"], out var h))
                {
                    Height = h;
                }
                foreach (var sct in ini.sections)
                {
                    if (sct.name != "Bookmark")
                    {
                        continue;
                    }
                    var name = sct["name"] ?? "?";
                    var path = sct["path"] ?? "";
                    var item = new GameListItem(name, path);
                    item.Notes         = sct["text"] ?? "";
                    item.IconPath      = sct["icon"];
                    item.CLIArgs       = sct["args"] ?? "";
                    item.ForceWindowed = sct["fwnd"] == "1";
                    AddGLI(item);
                }
            }
        }