Skip to content
Form1.cs 2.09 KiB
Newer Older
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;

namespace windows_spotlight_image_saver
{
    public partial class Form1 : Form
    {
		private string spotlightDir;
		private Button openInExplorerButton;
		
		private Label CreateSimpleLabel(string text, Int32 left, Int32 top)
	    {
			Label result = new Label();
			result.Text = text;
			result.Location = new Point(left, top);
			result.Size = new Size(result.PreferredWidth, result.PreferredHeight);
			return result;
		}

		private Button CreateSimpleButton(string text, Int32 left, Int32 top)
		{
			Button result = new Button();
			result.Text = text;
			result.Location = new Point(left, top);
			return result;
		}

		private string GetSpotlightDir()
		{
			string LocalAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
			return LocalAppData + "\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets";
		}
		
		private void openSpotlightDirInExplorer()
		{
			if (Directory.Exists(spotlightDir)) {
				ProcessStartInfo startInfo = new ProcessStartInfo {
					Arguments = spotlightDir,
					FileName = "explorer.exe"
				};
				Process.Start(startInfo);
			} else {
				MessageBox.Show(string.Format("{0} Directory does not exist!", spotlightDir));
			}
		}

		private void openInExplorerButton_Click(object sender, EventArgs e)
		{
			openSpotlightDirInExplorer();
		}

        public Form1()
        {
			string version = "0.1.0";
            InitializeComponent();
			this.Text = "Windows Spotlight Image Saver v" + version;

			Int32 left0 = 30;
			Int32 top0 = 30;
			spotlightDir = GetSpotlightDir();
			//this.Text = spotlightDir;
			openInExplorerButton = CreateSimpleButton("Open Spotlight Dir in Explorer", left0, top0);
			this.Controls.Add(openInExplorerButton);
			openInExplorerButton.Click += new EventHandler(openInExplorerButton_Click);
			openSpotlightDirInExplorer();