Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Threading;
- using Microsoft.VisualBasic;
- namespace HololensAppInstallation
- {
- public partial class Form1 : Form
- {
- public static Label statusLabel = new Label();
- public static Label errorTitleLabel = new Label();
- public static Label errorDescLabel = new Label();
- public static Button submitButton;
- public static Button restartButton;
- // If every entry is true, all threads are finished
- static List<bool> processesDone = new List<bool>();
- bool hasCheckingStarted = false;
- static int topBorder = 25;
- static Form form = new Form();
- static Dictionary<String, String> dropdownStates = new Dictionary<String, String>();
- public static List<CheckBox> checkboxesApps;
- static List<ComboBox> comboboxesApps;
- static int selectedAppCount = 0;
- List<Label> selectedAppList;
- String[] hololensAppPath;
- String desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- String[] completePath;
- public static String username = "";
- public static String password = "";
- public Form1()
- {
- String rootFolder = @"M:\projekte\Muenchen_Projekte\Executables\HoloLens_Installation";
- InitializeComponent();
- Paint += new PaintEventHandler(Form1_Paint);
- FormBorderStyle = FormBorderStyle.FixedSingle;
- MaximizeBox = false;
- MinimizeBox = false;
- Text = "HoloLens App Installation";
- BackColor = Color.White;
- hololensAppPath = Directory.GetDirectories(rootFolder);
- selectedAppList = new List<Label>();
- checkboxesApps = new List<CheckBox>();
- comboboxesApps = new List<ComboBox>();
- restartButton = new Button()
- {
- Size = new Size(35, 35),
- Top = 10,
- Left = 200,
- BackColor = Color.White,
- TextAlign = ContentAlignment.MiddleCenter
- };
- object o = Properties.Res
- Image img = (Image)o;
- //restartButton.Image = Image.FromFile(@"C:\Users\mckn\Desktop\cancel_img.png");
- Controls.Add(restartButton);
- statusLabel.Width = form.Width - 17;
- statusLabel.Height = 36;
- statusLabel.Top = 10;
- statusLabel.BackColor = Color.White;
- statusLabel.Text = "Done";
- statusLabel.ForeColor = Color.Gray;
- statusLabel.Font = new Font("Arial", 14);
- statusLabel.TextAlign = ContentAlignment.MiddleCenter;
- Controls.Add(statusLabel);
- errorTitleLabel.Width = (form.Width - 16) / 3;
- errorTitleLabel.Height = 36;
- errorTitleLabel.Top = 10;
- errorTitleLabel.BackColor = Color.White;
- errorTitleLabel.Text = "Fehler!";
- errorTitleLabel.ForeColor = Color.Red;
- errorTitleLabel.Font = new Font("Arial", 16);
- errorTitleLabel.TextAlign = ContentAlignment.MiddleCenter;
- Controls.Add(errorTitleLabel);
- errorTitleLabel.Visible = false;
- errorDescLabel.Width = Convert.ToInt32((form.Width - 16) / 1.5f);
- errorDescLabel.Height = 36;
- errorDescLabel.Top = 10;
- errorDescLabel.Left = errorTitleLabel.Width;
- errorDescLabel.BackColor = Color.White;
- errorDescLabel.Text = "";
- errorDescLabel.ForeColor = Color.Red;
- errorDescLabel.Font = new Font("Arial", 12);
- errorDescLabel.TextAlign = ContentAlignment.MiddleCenter;
- Controls.Add(errorDescLabel);
- errorDescLabel.Visible = false;
- for (int i = 0; i < hololensAppPath.Length; i++)
- {
- // Wenn das array nicht leer ist, besteht ein subdirectory
- String[] possibleSubdirectories = Directory.GetDirectories(hololensAppPath[i]);
- if (possibleSubdirectories.Length > 0)
- {
- CheckBox tempCheckBox = new CheckBox()
- {
- Left = 25,
- Top = topBorder + ((i + 1) * 40) - 4,
- Parent = this,
- Name = "CheckBox " + (i + 1),
- };
- for (int y = 0; y < possibleSubdirectories.Length; y++)
- {
- String[] substrings = possibleSubdirectories[y].Split('\\');
- possibleSubdirectories[y] = substrings[substrings.Length - 1];
- }
- String[] appSurname = possibleSubdirectories[0].Split('_');
- String appName = appSurname[0];
- for (int y = 0; y < possibleSubdirectories.Length; y++)
- {
- String[] substrings2 = possibleSubdirectories[y].Split('_');
- possibleSubdirectories[y] = substrings2[1];
- }
- Label tempLabel = new Label()
- {
- Left = 50,
- Top = topBorder + (i + 1) * 40,
- Parent = this,
- Name = "Label " + (i + 1),
- Text = appName
- };
- tempLabel.AutoSize = true;
- ComboBox tempComboBox = new ComboBox();
- tempComboBox.Items.AddRange(possibleSubdirectories);
- tempComboBox.Left = 70 + tempLabel.Width;
- tempComboBox.Top = topBorder + (i + 1) * 40;
- tempComboBox.Name = "ComboBox " + (i + 1);
- tempComboBox.MaxDropDownItems = possibleSubdirectories.Length;
- tempComboBox.TabIndex = 0;
- tempComboBox.SelectedIndex = 0;
- tempComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- tempComboBox.SelectedIndexChanged += new EventHandler(tempComboBox_SelectedIndexChanged);
- tempComboBoxInitialization(tempComboBox);
- comboboxesApps.Add(tempComboBox);
- selectedAppList.Add(tempLabel);
- checkboxesApps.Add(tempCheckBox);
- Controls.Add(tempComboBox);
- Controls.Add(tempCheckBox);
- }
- else
- {
- String[] substrings = hololensAppPath[i].Split('\\');
- String appName = substrings[substrings.Length - 1];
- Label tempLabel = new Label()
- {
- Left = 50,
- Top = topBorder + (i + 1) * 40,
- Parent = this,
- Name = "Label " + (i + 1),
- Text = appName
- };
- tempLabel.AutoSize = true;
- CheckBox tempCheckBox = new CheckBox()
- {
- Left = 25,
- Top = topBorder + ((i + 1) * 40) - 4,
- Parent = this,
- Name = "CheckBox " + (i + 1),
- };
- ComboBox tempComboBox = new ComboBox();
- comboboxesApps.Add(tempComboBox);
- selectedAppList.Add(tempLabel);
- checkboxesApps.Add(tempCheckBox);
- Controls.Add(tempLabel);
- Controls.Add(tempCheckBox);
- }
- Height += 40;
- }
- submitButton = new Button()
- {
- AutoSize = false,
- Width = 100,
- Text = "Installation starten"
- };
- submitButton.Top = Height - 100;
- submitButton.Left = (Width - submitButton.Width) / 2;
- Controls.Add(submitButton);
- submitButton.Click += new EventHandler(submitButton_Click);
- }
- private void submitButton_Click(object sender, EventArgs e)
- {
- statusLabel.Visible = true;
- errorTitleLabel.Visible = false;
- errorDescLabel.Visible = false;
- statusLabel.Text = "Installing";
- statusLabel.ForeColor = Color.Orange;
- Cursor = Cursors.WaitCursor;
- Directory.CreateDirectory(desktopPath + "\\tempFolder");
- for (int i = 0; i < checkboxesApps.Count; i++)
- {
- if (checkboxesApps[i].Checked)
- {
- selectedAppCount++;
- if (submitButton.Enabled)
- {
- submitButton.Enabled = false;
- foreach (CheckBox box in checkboxesApps)
- {
- box.Enabled = false;
- }
- foreach (ComboBox box in comboboxesApps)
- {
- box.Enabled = false;
- }
- }
- completePath = Directory.GetFiles(hololensAppPath[i]);
- String[] newCompletePath = new String[1];
- // if there is no file, but there are directories
- if (completePath.Length == 0)
- {
- String[] directories = Directory.GetDirectories(hololensAppPath[i]);
- foreach (String s in directories)
- {
- if (s.Contains(dropdownStates[comboboxesApps[i].Name]))
- {
- newCompletePath = Directory.GetFiles(s);
- }
- }
- }
- string copyToPath = desktopPath + "\\tempFolder" + "\\" + selectedAppList[i].Text + ".appxbundle";
- Thread copyThread;
- if (completePath.Length != 0)
- {
- copyThread = new Thread(() => FileCopyThread(completePath[0], copyToPath));
- }
- else
- {
- copyThread = new Thread(() => FileCopyThread(newCompletePath[0], copyToPath));
- }
- copyThread.Start();
- if (!hasCheckingStarted)
- {
- hasCheckingStarted = true;
- Thread threadCheckerThread = new Thread(() => AllThreadsDoneCheckerThread());
- threadCheckerThread.Start();
- }
- }
- }
- if (selectedAppCount == 0)
- {
- statusLabel.Visible = false;
- errorTitleLabel.Visible = true;
- errorDescLabel.Visible = true;
- errorDescLabel.Text = "Bitte mindestens eine App auswählen.";
- Cursor = Cursors.Default;
- }
- }
- public static void FileCopyThread(string copyFrom, string copyTo)
- {
- try
- {
- processesDone.Add(false);
- File.Copy(copyFrom, copyTo, true);
- processesDone.Remove(false);
- processesDone.Add(true);
- }
- catch (IOException e)
- {
- Console.WriteLine(e.StackTrace);
- }
- }
- public static void AllThreadsDoneCheckerThread()
- {
- Console.WriteLine("Checking for completion...");
- bool canProceed = true;
- if (selectedAppCount != processesDone.Count)
- {
- Console.WriteLine("Not all copythreads have been started.");
- canProceed = false;
- }
- foreach (bool b in processesDone)
- {
- Console.WriteLine(b.ToString());
- if (!b)
- {
- canProceed = false;
- }
- }
- if (!canProceed)
- {
- canProceed = true;
- Thread.Sleep(3000);
- Thread threadCheckerThread = new Thread(() => AllThreadsDoneCheckerThread());
- threadCheckerThread.Start();
- }
- else
- {
- username = Interaction.InputBox("Bitte den Benutzernamen für das Windows Device Portal eingeben.", "Device Portal Anmeldung", "admin", -1, -1);
- password = Interaction.InputBox("Bitte das Passwort für das Windows Device Portal eingeben.", "Device Portal Anmeldung", "hololensMMS16", -1, -1);
- APImanager.InstallHololensApp();
- }
- }
- private void tempComboBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- ComboBox changedComboBox = (ComboBox)sender;
- if (dropdownStates.ContainsKey(changedComboBox.Name))
- {
- dropdownStates.Remove(changedComboBox.Name);
- }
- dropdownStates.Add(changedComboBox.Name, changedComboBox.SelectedItem.ToString());
- }
- private void tempComboBoxInitialization(ComboBox box)
- {
- if (dropdownStates.ContainsKey(box.Name))
- {
- dropdownStates.Remove(box.Name);
- }
- dropdownStates.Add(box.Name, box.SelectedItem.ToString());
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- Pen pen = new Pen(Color.FromArgb(255, 226, 0, 116));
- pen.Width = 5;
- e.Graphics.DrawLine(pen, 0, 50, form.Width, 50);
- e.Graphics.DrawLine(pen, 0, 5, form.Width, 5);
- pen.Dispose();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement