Commits

Anonymous committed 50bc2f8

Added multi folder browing and added the ability to login

Comments (0)

Files changed (8)

Login.Designer.cs

+namespace RemoteLeecher
+{
+    partial class Login
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.btnLogin = new System.Windows.Forms.Button();
+            this.label1 = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
+            this.txtUsername = new System.Windows.Forms.TextBox();
+            this.txtPassword = new System.Windows.Forms.TextBox();
+            this.SuspendLayout();
+            // 
+            // btnLogin
+            // 
+            this.btnLogin.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
+            this.btnLogin.Location = new System.Drawing.Point(152, 74);
+            this.btnLogin.Name = "btnLogin";
+            this.btnLogin.Size = new System.Drawing.Size(75, 23);
+            this.btnLogin.TabIndex = 3;
+            this.btnLogin.Text = "Login";
+            this.btnLogin.UseVisualStyleBackColor = true;
+            this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Location = new System.Drawing.Point(8, 16);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(55, 13);
+            this.label1.TabIndex = 1;
+            this.label1.Text = "Username";
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Location = new System.Drawing.Point(8, 48);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(53, 13);
+            this.label2.TabIndex = 2;
+            this.label2.Text = "Password";
+            // 
+            // txtUsername
+            // 
+            this.txtUsername.Location = new System.Drawing.Point(78, 16);
+            this.txtUsername.Name = "txtUsername";
+            this.txtUsername.Size = new System.Drawing.Size(149, 20);
+            this.txtUsername.TabIndex = 1;
+            // 
+            // txtPassword
+            // 
+            this.txtPassword.Location = new System.Drawing.Point(78, 48);
+            this.txtPassword.Name = "txtPassword";
+            this.txtPassword.Size = new System.Drawing.Size(149, 20);
+            this.txtPassword.TabIndex = 2;
+            this.txtPassword.UseSystemPasswordChar = true;
+            // 
+            // Login
+            // 
+            this.AcceptButton = this.btnLogin;
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(254, 113);
+            this.Controls.Add(this.txtPassword);
+            this.Controls.Add(this.txtUsername);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.btnLogin);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
+            this.MaximizeBox = false;
+            this.MinimizeBox = false;
+            this.Name = "Login";
+            this.Text = "Login";
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Button btnLogin;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.TextBox txtUsername;
+        private System.Windows.Forms.TextBox txtPassword;
+    }
+}
+using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Windows.Forms;
+
+namespace RemoteLeecher
+{
+    public partial class Login : Form
+    {
+        public Login()
+        {
+            InitializeComponent();
+        }
+
+        private void btnLogin_Click(object sender, EventArgs e)
+        {
+            WebClient wc = new WebClient();
+
+            var test = new NameValueCollection();
+            test.Add("username", txtUsername.Text);
+            test.Add("password", txtPassword.Text);
+
+            if (false.ToString().ToLower() == Encoding.ASCII.GetString(wc.UploadValues("http://192.168.10.114:5000/login", test)).ToLower())
+            {
+                Application.Exit();
+            }
+            else
+            {
+                ServerBrowser browser = new ServerBrowser();
+                browser.UserName = txtUsername.Text;
+                browser.Password = txtPassword.Text;
+                browser.Show();
+                Hide();
+            }
+        }
+    }
+}
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>
         {
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
-            Application.Run(new ServerBrowser());
+            //Application.Run(new ServerBrowser());
+            Application.Run(new Login());
         }
     }
 }

RemoteLeecher.csproj

     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Login.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Login.Designer.cs">
+      <DependentUpon>Login.cs</DependentUpon>
+    </Compile>
     <Compile Include="ServerBrowser.cs">
       <SubType>Form</SubType>
     </Compile>
     </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <EmbeddedResource Include="Login.resx">
+      <DependentUpon>Login.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="ServerBrowser.resx">
       <DependentUpon>ServerBrowser.cs</DependentUpon>
     </EmbeddedResource>
       <Install>true</Install>
     </BootstrapperPackage>
   </ItemGroup>
+  <ItemGroup>
+    <WCFMetadata Include="Service References\" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.

RemoteLeecher.sln

+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoteLeecher", "RemoteLeecher.csproj", "{6C881097-2FE4-461F-A594-AF8F3E89497C}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x86 = Debug|x86
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{6C881097-2FE4-461F-A594-AF8F3E89497C}.Debug|x86.ActiveCfg = Debug|x86
+		{6C881097-2FE4-461F-A594-AF8F3E89497C}.Debug|x86.Build.0 = Debug|x86
+		{6C881097-2FE4-461F-A594-AF8F3E89497C}.Release|x86.ActiveCfg = Release|x86
+		{6C881097-2FE4-461F-A594-AF8F3E89497C}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

ServerBrowser.Designer.cs

             this.btnViewDebug = new System.Windows.Forms.Button();
             this.backgroundWorker = new System.ComponentModel.BackgroundWorker();
             this.lblProgress = new System.Windows.Forms.Label();
+            this.btnCalc = new System.Windows.Forms.Button();
             this.SuspendLayout();
             // 
             // btnRun
             this.btnCopy.TabIndex = 6;
             this.btnCopy.Text = "Perform Copy";
             this.btnCopy.UseVisualStyleBackColor = true;
-            this.btnCopy.Click += new System.EventHandler(this.button1_Click);
+            this.btnCopy.Click += new System.EventHandler(this.buttonPerformCopy_Click);
             // 
             // btnViewDebug
             // 
             this.lblProgress.Size = new System.Drawing.Size(0, 13);
             this.lblProgress.TabIndex = 10;
             // 
+            // btnCalc
+            // 
+            this.btnCalc.Location = new System.Drawing.Point(407, 342);
+            this.btnCalc.Name = "btnCalc";
+            this.btnCalc.Size = new System.Drawing.Size(147, 23);
+            this.btnCalc.TabIndex = 11;
+            this.btnCalc.Text = "Calculate Size Of Files";
+            this.btnCalc.UseVisualStyleBackColor = true;
+            this.btnCalc.Click += new System.EventHandler(this.btnCalc_Click);
+            // 
             // ServerBrowser
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(809, 371);
+            this.Controls.Add(this.btnCalc);
             this.Controls.Add(this.lblProgress);
             this.Controls.Add(this.btnViewDebug);
             this.Controls.Add(this.btnCopy);
             this.MaximizeBox = false;
             this.Name = "ServerBrowser";
             this.Text = "Remote Leecher";
+            this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.ServerBrowser_FormClosed);
             this.Load += new System.EventHandler(this.Form1_Load);
             this.ResumeLayout(false);
             this.PerformLayout();
         private System.Windows.Forms.Button btnViewDebug;
         private System.ComponentModel.BackgroundWorker backgroundWorker;
         private System.Windows.Forms.Label lblProgress;
+        private System.Windows.Forms.Button btnCalc;
     }
 }
 
         }
 
         string debugMessage = "";
+        public string UserName
+        {
+            get;
+            set;
+        }
+        public string Password
+        {
+            get;
+            set;
+        }
+        const string baseServerAddres = "http://192.168.10.114:5000/";
+        JArray rootFolder;
+        List<returnData> _objectArry = new List<returnData>();
+        ServerFolders serverFolders;
+        private DriveStatus copyDriveStatus;
 
         struct returnData
         {
             public JToken status;
         }
 
-        private JArray rootFolder;
-        private returnData _objectArry;
-        private ServerFolders serverFolders;
+        private void Form1_Load(object sender, EventArgs e)
+        {
+
+        }
 
         private void btnRun_Click(object sender, EventArgs e)
         {
             treeView1.Nodes.Clear();
+            treeView2.Nodes.Clear();
             lblProgress.Text = "Getting Latest Downloads";
             backgroundWorker.RunWorkerAsync();
             btnRun.Enabled = false;
             e.Effect = DragDropEffects.Move;
         }
 
-        private void button1_Click(object sender, EventArgs e)
+        private void buttonPerformCopy_Click(object sender, EventArgs e)
         {
             try
             {
+                //if (lblDriveStatus.Text == "False")
+                //{
+                //    MessageBox.Show("The copy drive is offline as such no copies can be performed");
+                //    return;
+                //}
+
                 List<string> uploadFolders = new List<string>();
                 string json = "";
                 foreach (TreeNode node in treeView2.Nodes[0].Nodes[0].Nodes)
                 {
                     //uploadFolders.Add(FindFolderInNodes(rootFolder, node.Text));
                     var folder = FindFolderInNodes(rootFolder, node.Text);
-                    if (folder[0] != null)
+                    if (folder != null)
                     {
                         uploadFolders.Add(FindFolderInNodes(rootFolder, node.Text)[0].ToString().Replace("\"", ""));
                     }
+                    else
+                    {
+                        uploadFolders.Add(node.Text);
+                    }
                 }
 
                 json = JsonConvert.SerializeObject(uploadFolders);
                 var test = new NameValueCollection { { "folders", json } };
                 ServicePointManager.Expect100Continue = false;
 
-                debugMessage = Encoding.ASCII.GetString(wc.UploadValues("http://republiccommandos.co.za/filelist/copyFolders", test));
+                debugMessage = Encoding.ASCII.GetString(wc.UploadValues(baseServerAddres + "copyFolders", test));
                 MessageBox.Show("Upload Complete");
             }
             catch (Exception exp)
 
         }
 
-        private void Form1_Load(object sender, EventArgs e)
-        {
-            //WebClient wc = new WebClient();
-
-            //var test = new NameValueCollection();
-            //test.Add("username", "jameel");
-            //if(false.ToString().ToLower() == Encoding.ASCII.GetString(wc.UploadValues("http://overlord:5000/login", test)).ToLower())
-            //{
-            //    Application.Exit();
-            //}
-        }
-
         private void button2_Click(object sender, EventArgs e)
         {
             MessageBox.Show(debugMessage);
         private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
         {
             WebClient wc = new WebClient();
+            List<string> folders = wc.DownloadString(baseServerAddres + "").Split(new string[] { ",{" }, StringSplitOptions.None).ToList();
+            foreach (string folder in folders)
+            {
+                string serverFolder = folder;
+                if (!serverFolder.StartsWith("{"))
+                {
+                    serverFolder = "{" + serverFolder;
+                }
+                var returnObject = JsonConvert.DeserializeObject(serverFolder, typeof(returnData));
+                _objectArry.Add((returnData)returnObject);
+            }
 
-            _objectArry = (returnData)JsonConvert.DeserializeObject(wc.DownloadString("http://republiccommandos.co.za/filelist/"), typeof(returnData));
-            serverFolders = (ServerFolders)JsonConvert.DeserializeObject(wc.DownloadString("http://republiccommandos.co.za/filelist/serverFolders"), typeof(ServerFolders));
-            var copyDriveStatus = (DriveStatus)JsonConvert.DeserializeObject(wc.DownloadString("http://republiccommandos.co.za/filelist/driveStatus"), typeof(DriveStatus));
+            serverFolders = (ServerFolders)JsonConvert.DeserializeObject(wc.DownloadString(baseServerAddres + "serverFolders"), typeof(ServerFolders));
+            copyDriveStatus = (DriveStatus)JsonConvert.DeserializeObject(wc.DownloadString(baseServerAddres + "driveStatus"), typeof(DriveStatus));
             //lblDriveStatus.Text = copyDriveStatus.status.ToString();
         }
 
         private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
         {
-            setupTree(_objectArry);
-            rootFolder = _objectArry.userFiles;
+            foreach (returnData data in _objectArry)
+            {
+                setupTree(data);
+                rootFolder = data.userFiles;
+            }
 
-            treeView2.Nodes[0].Nodes.Add(serverFolders.folders[0].Value<string>());
+            if (treeView2.Nodes.Count == 0)
+            {
+                treeView2.Nodes.Add("Drive");
+            }
+
+            treeView2.Nodes[0].Nodes.Add(UserName);
+            //treeView2.Nodes[0].Nodes.Add(serverFolders.folders[0].Value<string>());
             treeView2.ExpandAll();
 
             btnRun.Enabled = true;
             btnCopy.Enabled = true;
             btnViewDebug.Enabled = true;
 
+            lblDriveStatus.Text = copyDriveStatus.status.ToString().Replace("\"", "");
             lblProgress.Text = "Download Complete";
         }
+
+        private void ServerBrowser_FormClosed(object sender, FormClosedEventArgs e)
+        {
+            Application.Exit();
+        }
+
+        private void btnCalc_Click(object sender, EventArgs e)
+        {
+            try
+            {
+
+                List<string> uploadFolders = new List<string>();
+                string json = "";
+                foreach (TreeNode node in treeView2.Nodes[0].Nodes[0].Nodes)
+                {
+                    //uploadFolders.Add(FindFolderInNodes(rootFolder, node.Text));
+                    var folder = FindFolderInNodes(rootFolder, node.Text);
+                    if (folder != null)
+                    {
+                        uploadFolders.Add(FindFolderInNodes(rootFolder, node.Text)[0].ToString().Replace("\"", ""));
+                    }
+                    else
+                    {
+                        uploadFolders.Add(node.Text);
+                    }
+                }
+
+                json = JsonConvert.SerializeObject(uploadFolders);
+
+                WebClient wc = new WebClient();
+
+                var test = new NameValueCollection { { "folders", json } };
+                ServicePointManager.Expect100Continue = false;
+
+                debugMessage = Encoding.ASCII.GetString(wc.UploadValues(baseServerAddres + "calcFolderSize", test));
+            }
+            catch (Exception exp)
+            {
+                debugMessage = exp.Message;
+                MessageBox.Show("Upload Failed Check the debug info");
+            }
+        }
     }
 }