proff001

Untitled

Feb 16th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.98 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Net;
  7. using System.Windows.Forms;
  8.  
  9. namespace SchoolBackgroundChanger
  10. {
  11.     public class Form1 : Form
  12.     {
  13.         public string uName = Environment.UserName;
  14.  
  15.         public string copyPath;
  16.  
  17.         public int current_update = 2;
  18.  
  19.         private IContainer components = null;
  20.  
  21.         private Button btn_browse;
  22.  
  23.         private TextBox text_path;
  24.  
  25.         private ProgressBar progress_done;
  26.  
  27.         private Button btn_change;
  28.  
  29.         private Timer tick;
  30.  
  31.         private Label label1;
  32.  
  33.         private Button btn_updateNow;
  34.  
  35.         private Label label_updateStatus;
  36.  
  37.         public static bool CheckForInternetConnection()
  38.         {
  39.             bool result;
  40.             try
  41.             {
  42.                 using (WebClient webClient = new WebClient())
  43.                 {
  44.                     using (webClient.OpenRead("http://www.google.com"))
  45.                     {
  46.                         result = true;
  47.                     }
  48.                 }
  49.             }
  50.             catch
  51.             {
  52.                 result = false;
  53.             }
  54.             return result;
  55.         }
  56.  
  57.         public Form1()
  58.         {
  59.             this.InitializeComponent();
  60.             this.label_updateStatus.Text = "No Wifi Connection";
  61.             this.btn_updateNow.Enabled = false;
  62.             bool flag = Form1.CheckForInternetConnection();
  63.             if (flag)
  64.             {
  65.                 WebClient webClient = new WebClient();
  66.                 bool flag2 = File.Exists(Directory.GetCurrentDirectory() + "/autoUpdateBC.exe");
  67.                 if (flag2)
  68.                 {
  69.                     File.Delete(Directory.GetCurrentDirectory() + "/autoUpdateBC.exe");
  70.                     Process.Start("http://adf.ly/1iP5YL");
  71.                 }
  72.                 bool flag3 = Convert.ToInt32(webClient.DownloadString("https://backgroundchanger.000webhostapp.com/")) > this.current_update;
  73.                 if (flag3)
  74.                 {
  75.                     this.btn_updateNow.Enabled = true;
  76.                     this.label_updateStatus.Text = "Update Status: Ready";
  77.                 }
  78.                 else
  79.                 {
  80.                     this.btn_updateNow.Enabled = false;
  81.                     this.label_updateStatus.Text = "Update Status: Not Ready";
  82.                 }
  83.             }
  84.             this.tick.Enabled = false;
  85.         }
  86.  
  87.         private void button1_Click(object sender, EventArgs e)
  88.         {
  89.             OpenFileDialog openFileDialog = new OpenFileDialog();
  90.             openFileDialog.InitialDirectory = "c:\\";
  91.             openFileDialog.Filter = "PNG files (*.png)|*.png|JPG Files(*.jpg)|*.jpg|All files (*.*)|*.*";
  92.             openFileDialog.FilterIndex = 2;
  93.             openFileDialog.RestoreDirectory = true;
  94.             bool flag = openFileDialog.ShowDialog() == DialogResult.OK;
  95.             if (flag)
  96.             {
  97.                 this.text_path.Text = openFileDialog.FileName;
  98.             }
  99.         }
  100.  
  101.         private void btn_change_Click(object sender, EventArgs e)
  102.         {
  103.             bool flag = this.text_path.Text == "";
  104.             if (!flag)
  105.             {
  106.                 this.copyPath = "C:/Users/" + this.uName + "/AppData/Roaming/Microsoft/Windows/Themes";
  107.                 bool flag2 = File.Exists(this.copyPath + "/TranscodedWallpaper");
  108.                 if (flag2)
  109.                 {
  110.                     File.Delete(this.copyPath + "/TranscodedWallpaper");
  111.                 }
  112.                 bool flag3 = File.Exists(this.copyPath + "/CachedFiles/CachedImage_1366_768_POS3.jpg");
  113.                 if (flag3)
  114.                 {
  115.                     File.Delete(this.copyPath + "/CachedFiles/CachedImage_1366_768_POS3.jpg");
  116.                 }
  117.                 File.Copy(this.text_path.Text, this.copyPath + "/TranscodedWallpaper");
  118.                 File.Copy(this.text_path.Text, this.copyPath + "/CachedFiles/CachedImage_1366_768_POS3.jpg");
  119.                 Console.WriteLine(File.GetAttributes(this.text_path.Text));
  120.                 File.GetAttributes(this.text_path.Text);
  121.                 this.tick.Interval = 10;
  122.                 this.tick.Enabled = true;
  123.             }
  124.         }
  125.  
  126.         private void tick_Tick(object sender, EventArgs e)
  127.         {
  128.             this.progress_done.Value++;
  129.             bool flag = this.progress_done.Value == 100;
  130.             if (flag)
  131.             {
  132.                 Process process = new Process();
  133.                 Process[] processes = Process.GetProcesses();
  134.                 for (int i = 0; i < processes.Length; i++)
  135.                 {
  136.                     Process process2 = processes[i];
  137.                     bool flag2 = process2.ProcessName == "explorer";
  138.                     if (flag2)
  139.                     {
  140.                         process2.Kill();
  141.                     }
  142.                 }
  143.                 this.btn_change.Enabled = false;
  144.                 this.tick.Enabled = false;
  145.                 MessageBox.Show("Now just press (windows button) + TAB  if the screen is black\n\nThanks for using TDK's School background changer");
  146.             }
  147.         }
  148.  
  149.         private void label1_Click(object sender, EventArgs e)
  150.         {
  151.         }
  152.  
  153.         private void btn_updateNow_Click(object sender, EventArgs e)
  154.         {
  155.             WebClient webClient = new WebClient();
  156.             webClient.DownloadFile("https://backgroundchanger.000webhostapp.com/Downloads/autoUpdateBC.exe", "autoUpdateBC.exe");
  157.             Process.Start(Directory.GetCurrentDirectory() + "/autoUpdateBC.exe");
  158.             bool messageLoop = Application.MessageLoop;
  159.             if (messageLoop)
  160.             {
  161.                 Application.Exit();
  162.             }
  163.             else
  164.             {
  165.                 Environment.Exit(1);
  166.             }
  167.         }
  168.  
  169.         protected override void Dispose(bool disposing)
  170.         {
  171.             bool flag = disposing && this.components != null;
  172.             if (flag)
  173.             {
  174.                 this.components.Dispose();
  175.             }
  176.             base.Dispose(disposing);
  177.         }
  178.  
  179.         private void InitializeComponent()
  180.         {
  181.             this.components = new Container();
  182.             ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(Form1));
  183.             this.btn_browse = new Button();
  184.             this.text_path = new TextBox();
  185.             this.progress_done = new ProgressBar();
  186.             this.btn_change = new Button();
  187.             this.tick = new Timer(this.components);
  188.             this.label1 = new Label();
  189.             this.btn_updateNow = new Button();
  190.             this.label_updateStatus = new Label();
  191.             base.SuspendLayout();
  192.             this.btn_browse.Location = new Point(308, 13);
  193.             this.btn_browse.Name = "btn_browse";
  194.             this.btn_browse.Size = new Size(67, 20);
  195.             this.btn_browse.TabIndex = 0;
  196.             this.btn_browse.Text = "Browse";
  197.             this.btn_browse.UseVisualStyleBackColor = true;
  198.             this.btn_browse.Click += new EventHandler(this.button1_Click);
  199.             this.text_path.Location = new Point(12, 13);
  200.             this.text_path.Name = "text_path";
  201.             this.text_path.Size = new Size(290, 20);
  202.             this.text_path.TabIndex = 1;
  203.             this.progress_done.Location = new Point(12, 68);
  204.             this.progress_done.Name = "progress_done";
  205.             this.progress_done.Size = new Size(363, 23);
  206.             this.progress_done.TabIndex = 2;
  207.             this.btn_change.Location = new Point(12, 39);
  208.             this.btn_change.Name = "btn_change";
  209.             this.btn_change.Size = new Size(363, 23);
  210.             this.btn_change.TabIndex = 3;
  211.             this.btn_change.Text = "Change";
  212.             this.btn_change.UseVisualStyleBackColor = true;
  213.             this.btn_change.Click += new EventHandler(this.btn_change_Click);
  214.             this.tick.Tick += new EventHandler(this.tick_Tick);
  215.             this.label1.AutoSize = true;
  216.             this.label1.Location = new Point(9, 94);
  217.             this.label1.Name = "label1";
  218.             this.label1.Size = new Size(156, 13);
  219.             this.label1.TabIndex = 4;
  220.             this.label1.Text = "Made By:  Aleksander Evensen";
  221.             this.label1.Click += new EventHandler(this.label1_Click);
  222.             this.btn_updateNow.Location = new Point(381, 13);
  223.             this.btn_updateNow.Name = "btn_updateNow";
  224.             this.btn_updateNow.Size = new Size(141, 23);
  225.             this.btn_updateNow.TabIndex = 5;
  226.             this.btn_updateNow.Text = "Update";
  227.             this.btn_updateNow.UseVisualStyleBackColor = true;
  228.             this.btn_updateNow.Click += new EventHandler(this.btn_updateNow_Click);
  229.             this.label_updateStatus.AutoSize = true;
  230.             this.label_updateStatus.Font = new Font("Microsoft Sans Serif", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
  231.             this.label_updateStatus.Location = new Point(381, 47);
  232.             this.label_updateStatus.Name = "label_updateStatus";
  233.             this.label_updateStatus.Size = new Size(90, 15);
  234.             this.label_updateStatus.TabIndex = 6;
  235.             this.label_updateStatus.Text = "Update Status: ";
  236.             base.AutoScaleDimensions = new SizeF(6f, 13f);
  237.             base.AutoScaleMode = AutoScaleMode.Font;
  238.             base.ClientSize = new Size(534, 111);
  239.             base.Controls.Add(this.label_updateStatus);
  240.             base.Controls.Add(this.btn_updateNow);
  241.             base.Controls.Add(this.label1);
  242.             base.Controls.Add(this.btn_change);
  243.             base.Controls.Add(this.progress_done);
  244.             base.Controls.Add(this.text_path);
  245.             base.Controls.Add(this.btn_browse);
  246.             base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
  247.             this.MaximumSize = new Size(550, 150);
  248.             this.MinimumSize = new Size(550, 150);
  249.             base.Name = "Form1";
  250.             this.Text = "Background Changer | TDK";
  251.             base.ResumeLayout(false);
  252.             base.PerformLayout();
  253.         }
  254.     }
  255. }
Add Comment
Please, Sign In to add comment