public BmpForm() { InitializeComponent(); drawPen = new Pen(Brushes.Red, 1); RegistryInfo ri = new RegistryInfo(this); ri.AddProperty("LineColor"); DialogResult = DialogResult.Cancel; foreach (XCom.Interfaces.IXCImageFile xcf in XCom.SharedSpace.Instance.GetImageModList()) if (xcf.FileOptions[XCom.Interfaces.IXCImageFile.Filter.Bmp]) cbTypes.Items.Add(new cbItem(xcf, xcf.ExplorerDescription)); if (cbTypes.Items.Count > 0) cbTypes.SelectedIndex = 0; }
public AddinCategoryGroup(RegistryInfo reg, string name) { this.Registry = reg; this.Name = name; }
public AddinCategoryGroup (RegistryInfo reg, string name) { this.Registry = reg; this.Name = name; }
/// <summary> /// Creates the tileset editor. /// </summary> /// <param name="boxType"></param> /// <param name="labelGroup"></param> /// <param name="labelCategory"></param> /// <param name="labelTileset"></param> internal MapTreeTilesetInputBox( BoxType boxType, string labelGroup, string labelCategory, string labelTileset) { //LogFile.WriteLine(""); //LogFile.WriteLine("MapTreeTilesetInputBox cTor"); //LogFile.WriteLine(". labelGroup= " + labelGroup); //LogFile.WriteLine(". labelCategory= " + labelCategory); //LogFile.WriteLine(". labelTileset= " + labelTileset); InitializeComponent(); var regInfo = new RegistryInfo(RegistryInfo.TilesetEditor, this); // subscribe to Load and Closing events. regInfo.RegisterProperties(); Group = labelGroup; Category = labelCategory; Tileset = labelTileset; Inited = true; // don't let setting 'Tileset' run OnTilesetTextChanged() until // after 'BasePath' is initialized. Else ListTerrains() will throwup. var invalid = new List <char>(); char[] chars = Path.GetInvalidFileNameChars(); for (int i = 0; i != chars.Length; ++i) { invalid.Add(chars[i]); } invalid.Add(' '); // no spaces also. invalid.Add('.'); // and not dots. // TODO: hell i should just check for alpha-numeric and underscore. Old-school style. guaranteed. // Although users might not appreciate their old filenames getting too mangled. Invalid = invalid.ToArray(); // TODO: should disallow filenames like 'CON' and 'PRN' etc. also SetPasteButtonStuffer(); TileGroup = ResourceInfo.TileGroupInfo.TileGroups[Group] as TileGroup; switch (InputBoxType = boxType) { case BoxType.EditTileset: { Text = EditTileset; lblAddType.Text = "Modify existing tileset"; lblTilesetCurrent.Text = Tileset; btnFindTileset.Visible = btnFindDirectory.Visible = btnCreateMap.Visible = false; TilesetOriginal = String.Copy(Tileset); var tileset = TileGroup.Categories[Category][Tileset]; TerrainsOriginal = new List <string>(); foreach (string terrain in tileset.Terrains) { TerrainsOriginal.Add(String.Copy(terrain)); } BasePath = tileset.BasePath; break; } case BoxType.AddTileset: Text = AddTileset; lblAddType.Text = "Descriptor invalid"; lblTerrainChanges.Visible = lblHeaderTileset.Visible = lblTilesetCurrent.Visible = false; btnCreateMap.Enabled = btnTerrainCopy.Enabled = btnTerrainPaste.Enabled = false; string keyBaseDir = null; switch (TileGroup.GroupType) { case GameType.Ufo: keyBaseDir = SharedSpace.ResourceDirectoryUfo; break; case GameType.Tftd: keyBaseDir = SharedSpace.ResourceDirectoryTftd; break; } BasePath = SharedSpace.Instance.GetShare(keyBaseDir); break; } FileAddType = AddType.MapNone; tbTileset.Select(); }
public override async Task <bool> ExecuteAsync() { var dbFilename = DatabaseCacheFilePath; bool catalogUpdated = false; string filename = null; string registryCacheDirectory = null; string registryCachePath = null; string registryCacheFilePath = null; // Use a semaphore instead of a mutex because await may return to a thread other than the calling thread. using (var semaphore = GetDatabaseSemaphore()) { // Wait until file is downloaded/parsed if another download is already in session. // Allows user to open multiple npm windows and show progress bar without file-in-use errors. bool success = await Task.Run(() => semaphore.WaitOne(TimeSpan.FromMinutes(5))); if (!success) { // Return immediately so that the user can explicitly decide to refresh on failure. return(false); } Uri registryUrl = await GetRegistryUrl(); OnOutputLogged(string.Format(Resources.InfoRegistryUrl, registryUrl)); try { DbVersion version = null; RegistryInfo registryInfo = null; RegistryFileMapping registryFileMapping = null; Directory.CreateDirectory(Path.GetDirectoryName(dbFilename)); using (var db = new SQLiteConnection(dbFilename)) { // prevent errors from occurring when table doesn't exist db.CreateCatalogTableIfNotExists(); version = db.Table <DbVersion>().FirstOrDefault(); registryFileMapping = db.Table <RegistryFileMapping>().FirstOrDefault(info => info.RegistryUrl == registryUrl.ToString()); } registryCacheDirectory = registryFileMapping != null ? registryFileMapping.DbFileLocation : Guid.NewGuid().ToString(); registryCachePath = Path.Combine(CachePath, registryCacheDirectory); registryCacheFilePath = Path.Combine(registryCachePath, RegistryCacheFilename); Directory.CreateDirectory(Path.GetDirectoryName(registryCacheFilePath)); if (File.Exists(registryCacheFilePath)) { using (var registryDb = new SQLiteConnection(registryCacheFilePath)) { // prevent errors from occurring when table doesn't exist registryDb.CreateRegistryTableIfNotExists(); registryInfo = registryDb.Table <RegistryInfo>().FirstOrDefault(); } } bool correctDatabaseSchema = version != null && version.Id == _databaseSchemaVersion; bool incrementalUpdate = correctDatabaseSchema && _forceDownload && registryInfo != null && registryInfo.Revision > 0; bool fullUpdate = correctDatabaseSchema && (registryInfo == null || registryInfo.Revision <= 0); if (!correctDatabaseSchema) { OnOutputLogged(Resources.InfoCatalogUpgrade); SafeDeleteFolder(CachePath); CreateCatalogDatabaseAndInsertEntries(dbFilename, registryUrl, registryCacheDirectory); filename = await UpdatePackageCache(registryUrl, CachePath); catalogUpdated = true; } else if (incrementalUpdate) { filename = await UpdatePackageCache(registryUrl, registryCachePath, registryInfo.Revision); catalogUpdated = true; } else if (fullUpdate) { CreateCatalogDatabaseAndInsertEntries(dbFilename, registryUrl, registryCacheDirectory); filename = await UpdatePackageCache(registryUrl, registryCachePath); catalogUpdated = true; } if (catalogUpdated) { var fileInfo = new FileInfo(filename); OnOutputLogged(String.Format(Resources.InfoReadingBytesFromPackageCache, fileInfo.Length, filename, fileInfo.LastWriteTime)); using (var reader = new StreamReader(filename)) { await Task.Run(() => ParseResultsAndAddToDatabase(reader, registryCacheFilePath, registryUrl.ToString())); } } using (var db = new SQLiteConnection(registryCacheFilePath)) { db.CreateRegistryTableIfNotExists(); ResultsCount = db.Table <CatalogEntry>().Count(); } } catch (Exception ex) { if (ex is StackOverflowException || ex is OutOfMemoryException || ex is ThreadAbortException || ex is AccessViolationException) { throw; } // assume the results are corrupted OnOutputLogged(ex.ToString()); throw; } finally { if (ResultsCount == null) { OnOutputLogged(string.Format(Resources.DownloadOrParsingFailed, CachePath)); SafeDeleteFolder(registryCacheDirectory); } else if (ResultsCount <= 0) { // Database file exists, but is corrupt. Delete database, so that we can download the file next time arround. OnOutputLogged(string.Format(Resources.DatabaseCorrupt, dbFilename)); SafeDeleteFolder(registryCacheDirectory); } semaphore.Release(); } } LastRefreshed = File.GetLastWriteTime(registryCacheFilePath); OnOutputLogged(String.Format(Resources.InfoCurrentTime, DateTime.Now)); OnOutputLogged(String.Format(Resources.InfoLastRefreshed, LastRefreshed)); if (ResultsCount != null) { OnOutputLogged(String.Format(Resources.InfoNumberOfResults, ResultsCount)); } return(true); }
public PckViewForm() { InitializeComponent(); #region shared space information sharedSpace = SharedSpace.Instance; if (sharedSpace.GetObj("xConsole") == null) { console = (ConsoleForm)sharedSpace.GetObj("xConsole", new ConsoleForm()); console.FormClosing += delegate(object sender, FormClosingEventArgs e) { e.Cancel = true; console.Hide(); }; } console.Show(); sharedSpace.GetObj("PckView",this); sharedSpace.GetObj("AppDir", Environment.CurrentDirectory); sharedSpace.GetObj("CustomDir", Environment.CurrentDirectory + "\\custom"); sharedSpace.GetObj("SettingsDir", Environment.CurrentDirectory + "\\settings"); xConsole.AddLine("Current directory: " + sharedSpace["AppDir"]); xConsole.AddLine("Custom directory: " + sharedSpace["CustomDir"].ToString()); #endregion v = TotalViewPck.Instance; v.Dock = DockStyle.Fill; this.Controls.Add(v); v.View.DoubleClick += new EventHandler(doubleClick); v.ViewClicked += new PckViewMouseClicked(viewClicked); v.XCImageCollectionSet += new XCImageCollectionHandler(v_XCImageCollectionSet); v.ContextMenu = makeContextMenu(); sharedSpace["Palettes"] = new Dictionary<string, Palette>(); palMI = new Dictionary<Palette, MenuItem>(); selectedMI = AddPalette(Palette.TFTDBattle, miPalette); AddPalette(Palette.TFTDGeo, miPalette); AddPalette(Palette.TFTDGraph, miPalette); AddPalette(Palette.TFTDResearch, miPalette); AddPalette(Palette.UFOBattle, miPalette); AddPalette(Palette.UFOGeo, miPalette); AddPalette(Palette.UFOGraph, miPalette); AddPalette(Palette.UFOResearch, miPalette); editor = new Editor(null); editor.Closing += new CancelEventHandler(editorClosing); currPal = Palette.TFTDBattle; RegistryInfo ri = new RegistryInfo(this, "PckView"); ri.AddProperty("FilterIndex"); ri.AddProperty("SelectedPalette"); if (!File.Exists("hq2xa.dll")) miHq2x.Visible = false; loadedTypes = new LoadOfType<IXCImageFile>(); loadedTypes.OnLoad += new LoadOfType<IXCImageFile>.TypeLoadDelegate(loadedTypes_OnLoad); sharedSpace["ImageMods"] = loadedTypes.AllLoaded; //loadedTypes.OnLoad += new LoadOfType<IXCFile>.TypeLoadDelegate(sortLoaded); loadedTypes.LoadFrom(Assembly.GetExecutingAssembly()); loadedTypes.LoadFrom(Assembly.GetAssembly(typeof(XCom.Interfaces.IXCImageFile))); if (Directory.Exists(sharedSpace["CustomDir"].ToString())) { //Console.WriteLine("Custom directory exists: "+sharedSpace["CustomDir"].ToString()); xConsole.AddLine("Custom directory exists: " + sharedSpace["CustomDir"].ToString()); foreach (string s in Directory.GetFiles(sharedSpace["CustomDir"].ToString())) if (s.EndsWith(".dll")) { xConsole.AddLine("Loading dll: " + s); loadedTypes.LoadFrom(Assembly.LoadFrom(s)); } else if (s.EndsWith(xcProfile.PROFILE_EXT)) foreach (xcProfile ip in ImgProfile.LoadFile(s)) loadedTypes.Add(ip); } osFilter = new OpenSaveFilter(); osFilter.SetFilter(IXCImageFile.Filter.Open); openDictionary = new Dictionary<int, IXCImageFile>(); saveDictionary = new Dictionary<int, IXCImageFile>(); osFilter.SetFilter(IXCImageFile.Filter.Open); string filter = loadedTypes.CreateFilter(osFilter, openDictionary); openFile.Filter = filter; }
public bool IsEqualTo(RegistryInfo registryInfo) { var comparer = new UpmRegistryClient.RegistryInfoComparer(); return(comparer.Equals(m_RegistryInfo, registryInfo)); }
private RegistryInfo CopyOriginal(RegistryInfo original) { return(original != null ? new RegistryInfo(original.id, original.name, original.url, original.scopes?.Clone() as string[], original.isDefault, original.capabilities) : null); }
public void SetRegistryInfo(RegistryInfo registryInfo) { // make a copy to prevent alteration of underlying scoped registries // list when undoing selection m_RegistryInfo = CopyOriginal(registryInfo); }
public PropertyForm() { InitializeComponent(); RegistryInfo ri = new RegistryInfo(this, "OptionsForm"); }