| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- using Microsoft.Win32;
- using System;
- using System.IO;
- using System.Windows.Forms;
- using System;
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net;
- using System.IO.Compression;
- namespace QGIS_Installer
- {
- public partial class Form1 : Form
- {
- List<RegistryKey> list = new List<RegistryKey>();
- RegistryKey key3_4;
- RegistryKey key3_0;
- RegistryKey key3_6;
- RegistryKey key3_10;
- RegistryKey key3_8;
- RegistryKey key3_12;
- public Form1()
- {
- InitializeComponent();
- }
-
- private void copyFiles(string SourcePath, string DestinationPath)
- {
- // string dest = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
- // string SourcePath = "C:\\Users\\Honza\\Documents\\testcopy\\folder1";
- // string DestinationPath = "C:\\Users\\Honza\\Documents\\testcopy\\folder2";
- try
- {
- foreach (string dirPath in Directory.GetDirectories(SourcePath, "*",
- SearchOption.AllDirectories))
- Directory.CreateDirectory(dirPath.Replace(SourcePath, DestinationPath));
- // Copy all the files &Replaces any files with the same name
- foreach (string newPath in Directory.GetFiles(SourcePath, "*.*",
- SearchOption.AllDirectories))
- File.Copy(newPath, newPath.Replace(SourcePath, DestinationPath), true);
- }
- catch (Exception ex) //just for demonstration...it's always best to handle specific exceptions
- {
- //label1.ForeColor = System.Drawing.Color.Red;
- label1.Text = "You must run program as administrator!";
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- RegistryKey key ;
- String s = comboBox1.Text;
- if (s == "QGIS 3_4")
- key = key3_4;
- else if (s == "QGIS 3_10")
- key = key3_10;
- else if (s == "QGIS 3_0")
- key = key3_0;
- else if (s == "QGIS 3_8")
- key = key3_8;
- else if (s == "QGIS 3_12")
- key = key3_12;
- else
- key = null;
-
- label1.Text = "Installing";
- downloadPlugin(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
- //using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
- // //using (var key = hklm.OpenSubKey(@"Software\\QGIS 3.4"))
- // foreach (RegistryKey key in list)
- // {
-
- string o = key.GetValue("InstallPath").ToString();
-
- //o = o + "\\apps\\Python37\\Lib\\site-packages"
- string out1 = o + "\\apps\\Python37\\Lib\\site-packages";
- string out2 = o + "\\apps\\Python37\\Scripts\\flask.exe";
- string out3 = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\AppData\\Roaming\\QGIS\\QGIS3\\profiles\\default\\python\\plugins\\atlas";
- string input = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\packages";
- copyFiles(input, out1.ToString());
- string input2 = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\flask.exe";
- try
- {
- File.Copy(input2, out2);
- }
- catch (Exception ex)
- {
- label1.ForeColor = System.Drawing.Color.Red;
- label1.Text = "You must run program as administrator!";
- }
- if (isPluginInstalled(o))
- {
-
-
- string input3 = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\atlas";
- copyFiles(input3, out3);
- }
- else
- {
- if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\AppData\\Roaming\\QGIS\\QGIS3\\profiles\\default\\python\\plugins"))
- {
- label1.Text = " is ready!";
- Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\AppData\\Roaming\\QGIS\\QGIS3\\profiles\\default\\python\\plugins");
-
- }
- string input3 = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\atlas";
- copyFiles(input3, out3);
- }
-
-
- //}
- checkStatus();
- if (label2.Text == "Installed" && label3.Text == "Installed" && label4.Text == "Installed" && label5.Text == "Installed" && label6.Text == "Installed")
- {
- label1.ForeColor = System.Drawing.Color.Green;
- label1.Text = "Plugin is ready!";
- }
- else
- {
- label1.Text = "You must run program as administrator!";
- }
-
- }
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- getVersions();
- label1.Text = "";
- // checkStatus();
- if (label2.Text == "Installed" && label3.Text == "Installed" && label4.Text == "Installed" && label5.Text == "Installed" && label6.Text == "Installed")
- {
- // label1.ForeColor = System.Drawing.Color.Green;
- label1.Text = "Plugin is already installed.";
- }
- else
- {
- label1.Text = "Plugin is not installed.";
- }
- if (list.Count == 0)
- {
- button3.Enabled = false;
- label1.Text = "QGIS is not installed.";
- }
- }
- private void downloadPlugin(string path)
- {
- WebClient Client = new WebClient();
- Client.DownloadFile("https://gitlab.com/Vrobel/atlas/-/archive/master/atlas-master.zip", path + "\\atlas.zip");
- try { Directory.Delete(path + "\\atlas", true); }
- catch { }
-
- ZipFile.ExtractToDirectory(path + "\\atlas.zip", path);
- Directory.Move(path + "\\atlas-master", path + "\\atlas");
- try { Directory.Delete(path + "\\atlas-master", true); }
- catch { }
- }
- private bool isPluginInstalled(string o)
- {
- string plugin = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\AppData\\Roaming\\QGIS\\QGIS3\\profiles\\default\\python\\plugins\\atlas\\__init__.py";
- string plugin2 = o + @"\apps\qgis-ltr\python\plugins\atlas\__init__.py";
- if (File.Exists(plugin) || File.Exists(plugin2))
- {
- return true;
- }
- else
- {
- return false;
- }
-
- }
- private void label9_Click(object sender, EventArgs e)
- {
- }
- private void checkStatus()
- {
- using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
- using (var key = hklm.OpenSubKey(@"Software\\QGIS 3.4"))
- {
- string o = key.GetValue("InstallPath").ToString();
- string wergzeug = o + @"\apps\Python37\Lib\site-packages\werkzeug\test.py";
- if (File.Exists(wergzeug))
- {
- label2.Text = "Installed";
- }
- else
- {
- label2.Text = "Not Installed";
- }
- string flask = o + @"\apps\Python37\Lib\site-packages\flask\__init__.py";
- string flask2 = o + @"\apps\Python37\Scripts\flask.exe";
- if (File.Exists(flask) && File.Exists(flask2))
- {
- label3.Text = "Installed";
- }
- else
- {
- label3.Text = "Not Installed";
- }
- string click = o + @"\apps\Python37\Lib\site-packages\click\__init__.py";
- if (File.Exists(click))
- {
- label4.Text = "Installed";
- }
- else
- {
- label4.Text = "Not Installed";
- }
- string dangerous = o + @"\apps\Python37\Lib\site-packages\itsdangerous\__init__.py";
- if (File.Exists(dangerous))
- {
- label5.Text = "Installed";
- }
- else
- {
- label5.Text = "Not Installed";
- }
- string plugin = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\AppData\\Roaming\\QGIS\\QGIS3\\profiles\\default\\python\\plugins\\atlas\\__init__.py";
- string plugin2 = o + @"\apps\qgis-ltr\python\plugins\atlas\__init__.py";
- if (File.Exists(plugin) || File.Exists(plugin2))
- {
- label6.Text = "Installed";
- }
- else
- {
- label6.Text = "Not Installed";
- }
- }
- }
- private void checkStatus(RegistryKey key)
- {
-
- string o = key.GetValue("InstallPath").ToString();
- string wergzeug = o + @"\apps\Python37\Lib\site-packages\werkzeug\test.py";
- if (File.Exists(wergzeug))
- {
- label2.Text = "Installed";
- }
- else
- {
- label2.Text = "Not Installed";
- }
- string flask = o + @"\apps\Python37\Lib\site-packages\flask\__init__.py";
- string flask2 = o + @"\apps\Python37\Scripts\flask.exe";
- if (File.Exists(flask) && File.Exists(flask2))
- {
- label3.Text = "Installed";
- }
- else
- {
- label3.Text = "Not Installed";
- }
- string click = o + @"\apps\Python37\Lib\site-packages\click\__init__.py";
- if (File.Exists(click))
- {
- label4.Text = "Installed";
- }
- else
- {
- label4.Text = "Not Installed";
- }
- string dangerous = o + @"\apps\Python37\Lib\site-packages\itsdangerous\__init__.py";
- if (File.Exists(dangerous))
- {
- label5.Text = "Installed";
- }
- else
- {
- label5.Text = "Not Installed";
- }
- string plugin = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\AppData\\Roaming\\QGIS\\QGIS3\\profiles\\default\\python\\plugins\\atlas\\__init__.py";
- string plugin2 = o + @"\apps\qgis-ltr\python\plugins\atlas\__init__.py";
- if (File.Exists(plugin) || File.Exists(plugin2))
- {
- label6.Text = "Installed";
- }
- else
- {
- label6.Text = "Not Installed";
- }
-
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
- downloadPlugin(path);
- }
- private void label12_Click(object sender, EventArgs e)
- {
- }
- // private void button2_Click(object sender, EventArgs e)
- private void getVersions()
- {
- using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)) {
-
- key3_4 = hklm.OpenSubKey(@"Software\\QGIS 3.4");
- key3_0 = hklm.OpenSubKey(@"Software\\QGIS 3.0");
- key3_6 = hklm.OpenSubKey(@"Software\\QGIS 3.6");
- key3_10 = hklm.OpenSubKey(@"Software\\QGIS 3.10");
- key3_8 = hklm.OpenSubKey(@"Software\\QGIS 3.8");
- key3_12 = hklm.OpenSubKey(@"Software\\QGIS 3.12");
- if (key3_4 != null) {
- list.Add(key3_4);
- label13.Text = "QGIS 3_4 detected \n";
- comboBox1.Items.Add("QGIS 3_4");
- comboBox1.Text = "QGIS 3_4";
- // checkStatus(key3_4);
- }
- if (key3_0 != null)
- {
- list.Add(key3_0);
- label13.Text = label13.Text + "QGIS 3_0 detected \n";
- comboBox1.Items.Add("QGIS 3_0");
- comboBox1.Text = "QGIS 3_0";
- // checkStatus(key3_0);
- }
- if (key3_6 != null)
- {
- list.Add(key3_6);
- label13.Text = label13.Text + "QGIS 3_6 detected \n";
- comboBox1.Items.Add("QGIS 3_6");
- comboBox1.Text = "QGIS 3_6";
- // checkStatus(key3_6);
- }
- if (key3_10 != null)
- {
- list.Add(key3_10);
- label13.Text = label13.Text + "QGIS 3_10 detected \n";
- comboBox1.Items.Add("QGIS 3_10");
- comboBox1.Text = "QGIS 3_10";
- // checkStatus(key3_10);
- }
- if (key3_8 != null) {
- list.Add(key3_8);
- label13.Text = label13.Text + "QGIS 3_8 detected \n";
- comboBox1.Items.Add("QGIS 3_8");
- comboBox1.Text = "QGIS 3_8";
- // checkStatus(key3_8);
- }
- if (key3_12 != null)
- {
- list.Add(key3_8);
- label13.Text = label13.Text + "QGIS 3_12 detected \n";
- comboBox1.Items.Add("QGIS 3_12");
- comboBox1.Text = "QGIS 3_12";
- // checkStatus(key3_12);
- }
-
- }
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- String s = comboBox1.Text;
- if (s == "QGIS 3_4")
- checkStatus(key3_4);
- if (s == "QGIS 3_10")
- checkStatus(key3_10);
- if (s == "QGIS 3_0")
- checkStatus(key3_0);
- if (s == "QGIS 3_8")
- checkStatus(key3_8);
- if (s == "QGIS 3_12")
- checkStatus(key3_12);
- if (label2.Text == "Installed" && label3.Text == "Installed" && label4.Text == "Installed" && label5.Text == "Installed" && label6.Text == "Installed") {
- // label1.ForeColor = System.Drawing.Color.Green;
- label1.Text = "Plugin is already installed.";
- }
- else {
- label1.Text = "Plugin is not installed.";
- }
- }
- }
-
- }
|