/// <summary> /// Reset the tile for the given application. /// </summary> /// <param name="app">Application shortcut and executable information</param> /// <returns>true if the tile was reset, false if nothing was done.</returns> public static bool ResetTileSet(AppShortcut app) { // App paths string appPath = Path.GetDirectoryName(app.ExecutablePath); string assetsPath = Path.Combine(appPath, AssetsConstants.AssetsFolderName); string xml = Path.Combine(appPath, Path.GetFileNameWithoutExtension(app.ExecutablePath) + AssetsConstants.VisualElementsManifestXmlFileExtension); string mediumTilePath = Path.Combine(assetsPath, AssetsConstants.MediumTileFileName); string smallTilePath = Path.Combine(assetsPath, AssetsConstants.SmallTileFileName); // Clean XML file and assets if (File.Exists(xml) && File.Exists(mediumTilePath) && File.Exists(smallTilePath)) { File.Delete(xml); File.Delete(mediumTilePath); File.Delete(smallTilePath); Directory.Delete(assetsPath); File.SetLastWriteTime(app.ShortcutPath, DateTime.Now); return(true); } else { return(false); } }
/// <summary> /// Generate tiles for an application and update the shortcut. /// </summary> /// <param name="tileConfig">Tile generation configuration</param> /// <param name="app">Application shortcut and executable information</param> /// <param name="sizes">Tiles dimensions</param> /// <param name="overwrite">Overwrite existing tiles</param> public static void GenerateTileSet(TileConfig tileConfig, AppShortcut app, TileSetSizes sizes, bool overwrite = false) { // Prepare assets directory and make some verifications string appPath = Path.GetDirectoryName(app.ExecutablePath); string assetsPath = Path.Combine(appPath, AssetsConstants.AssetsFolderName); string xml = Path.Combine(appPath, Path.GetFileNameWithoutExtension(app.ExecutablePath) + AssetsConstants.VisualElementsManifestXmlFileExtension); string mediumTilePath = Path.Combine(assetsPath, AssetsConstants.MediumTileFileName); string smallTilePath = Path.Combine(assetsPath, AssetsConstants.SmallTileFileName); if (File.Exists(xml) && Directory.Exists(assetsPath) && !File.Exists(mediumTilePath) && !File.Exists(smallTilePath)) { // Assets (not generated by Tile) already exist in the application directory throw new Exception("Application already have built-in custom assets"); } else if (!overwrite && File.Exists(xml)) { // Custom assets (generated by Tile) already exist throw new Exception("Custom assets already exist, delete them or set the override flag to true"); } // else: create the assets directory Directory.CreateDirectory(assetsPath); // Generate the XML file (background color, logo paths, foreground color, and XML filename) File.WriteAllText(xml, GenerateXMLVisualElements( tileConfig.BackgroundColorAsObj, tileConfig.ForegroundTextAsEnum, tileConfig.ShowNameOnMediumTile)); // Tile generation Image mediumTile, smallTile; if (tileConfig.GenerationModeAsEnum == TileGenerationMode.Custom) { mediumTile = GenerateTile(sizes.Medium.TileSize, tileConfig.BackgroundColorAsObj, tileConfig.IconPath, sizes.Medium.TileSize); smallTile = GenerateTile(sizes.Small.TileSize, tileConfig.BackgroundColorAsObj, tileConfig.IconPath, sizes.Small.TileSize); } else { int shift = (int)(ADJUSTED_ICON_Y_SHIFT * sizes.Medium.TileSize.Height); mediumTile = GenerateTile(sizes.Medium.TileSize, tileConfig.BackgroundColorAsObj, tileConfig.IconPath, sizes.Medium.IconSize.Scale(tileConfig.IconScale.MediumTile), tileConfig.GenerationModeAsEnum == TileGenerationMode.Adjusted ? shift : 0); smallTile = GenerateTile(sizes.Small.TileSize, tileConfig.BackgroundColorAsObj, tileConfig.IconPath, sizes.Small.IconSize.Scale(tileConfig.IconScale.SmallTile)); } // Save tiles in assets directory mediumTile.Save(mediumTilePath, ImageFormat.Png); smallTile.Save(smallTilePath, ImageFormat.Png); // Set shortcut last write time to now (to update tile) File.SetLastWriteTime(app.ShortcutPath, DateTime.Now); }