diff --git a/.vs/ProjectEvaluation/titanic.metadata.v5.2 b/.vs/ProjectEvaluation/titanic.metadata.v5.2 index 0a4bd9c..59f626c 100644 Binary files a/.vs/ProjectEvaluation/titanic.metadata.v5.2 and b/.vs/ProjectEvaluation/titanic.metadata.v5.2 differ diff --git a/.vs/ProjectEvaluation/titanic.projects.v5.2 b/.vs/ProjectEvaluation/titanic.projects.v5.2 index 471e248..50a5486 100644 Binary files a/.vs/ProjectEvaluation/titanic.projects.v5.2 and b/.vs/ProjectEvaluation/titanic.projects.v5.2 differ diff --git a/.vs/Titanic/DesignTimeBuild/.dtbcache.v2 b/.vs/Titanic/DesignTimeBuild/.dtbcache.v2 index 2b02892..64ef373 100644 Binary files a/.vs/Titanic/DesignTimeBuild/.dtbcache.v2 and b/.vs/Titanic/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/Titanic/FileContentIndex/27971631-f132-4e43-9932-dbb7e2b790ee.vsidx b/.vs/Titanic/FileContentIndex/27971631-f132-4e43-9932-dbb7e2b790ee.vsidx new file mode 100644 index 0000000..7f9a8a9 Binary files /dev/null and b/.vs/Titanic/FileContentIndex/27971631-f132-4e43-9932-dbb7e2b790ee.vsidx differ diff --git a/.vs/Titanic/FileContentIndex/5e500cb8-fd32-4f47-9fe1-daa113f0997c.vsidx b/.vs/Titanic/FileContentIndex/5e500cb8-fd32-4f47-9fe1-daa113f0997c.vsidx deleted file mode 100644 index c80ac3f..0000000 Binary files a/.vs/Titanic/FileContentIndex/5e500cb8-fd32-4f47-9fe1-daa113f0997c.vsidx and /dev/null differ diff --git a/.vs/Titanic/FileContentIndex/764ed724-0897-476d-82e1-95f32cfc6fe2.vsidx b/.vs/Titanic/FileContentIndex/764ed724-0897-476d-82e1-95f32cfc6fe2.vsidx new file mode 100644 index 0000000..6db35c5 Binary files /dev/null and b/.vs/Titanic/FileContentIndex/764ed724-0897-476d-82e1-95f32cfc6fe2.vsidx differ diff --git a/.vs/Titanic/FileContentIndex/846b6baa-f343-4b11-8529-52ef89be2c82.vsidx b/.vs/Titanic/FileContentIndex/846b6baa-f343-4b11-8529-52ef89be2c82.vsidx deleted file mode 100644 index 0c81147..0000000 Binary files a/.vs/Titanic/FileContentIndex/846b6baa-f343-4b11-8529-52ef89be2c82.vsidx and /dev/null differ diff --git a/.vs/Titanic/FileContentIndex/a263dd3e-4aca-4ae9-87e3-4686d6127164.vsidx b/.vs/Titanic/FileContentIndex/a263dd3e-4aca-4ae9-87e3-4686d6127164.vsidx deleted file mode 100644 index 818e4c5..0000000 Binary files a/.vs/Titanic/FileContentIndex/a263dd3e-4aca-4ae9-87e3-4686d6127164.vsidx and /dev/null differ diff --git a/.vs/Titanic/FileContentIndex/ca41507d-9bee-4658-abd3-be9c589d6a1a.vsidx b/.vs/Titanic/FileContentIndex/ca41507d-9bee-4658-abd3-be9c589d6a1a.vsidx deleted file mode 100644 index 84c1ee3..0000000 Binary files a/.vs/Titanic/FileContentIndex/ca41507d-9bee-4658-abd3-be9c589d6a1a.vsidx and /dev/null differ diff --git a/.vs/Titanic/FileContentIndex/d8068ee3-a65c-4e22-a75b-f185a8edddc7.vsidx b/.vs/Titanic/FileContentIndex/d8068ee3-a65c-4e22-a75b-f185a8edddc7.vsidx new file mode 100644 index 0000000..3ffb016 Binary files /dev/null and b/.vs/Titanic/FileContentIndex/d8068ee3-a65c-4e22-a75b-f185a8edddc7.vsidx differ diff --git a/.vs/Titanic/FileContentIndex/de624c4d-1a25-408b-9a56-fd5bb01e5e7b.vsidx b/.vs/Titanic/FileContentIndex/de624c4d-1a25-408b-9a56-fd5bb01e5e7b.vsidx new file mode 100644 index 0000000..5e4098f Binary files /dev/null and b/.vs/Titanic/FileContentIndex/de624c4d-1a25-408b-9a56-fd5bb01e5e7b.vsidx differ diff --git a/.vs/Titanic/v17/.futdcache.v2 b/.vs/Titanic/v17/.futdcache.v2 index c48dc1b..0656388 100644 Binary files a/.vs/Titanic/v17/.futdcache.v2 and b/.vs/Titanic/v17/.futdcache.v2 differ diff --git a/.vs/Titanic/v17/.suo b/.vs/Titanic/v17/.suo index 0a90480..0a0db55 100644 Binary files a/.vs/Titanic/v17/.suo and b/.vs/Titanic/v17/.suo differ diff --git a/Titanic/AddNewProjectFromGit.Designer.cs b/Titanic/AddNewProjectFromGit.Designer.cs new file mode 100644 index 0000000..f139ee5 --- /dev/null +++ b/Titanic/AddNewProjectFromGit.Designer.cs @@ -0,0 +1,133 @@ +namespace Titanic +{ + partial class AddNewProjectFromGit + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.listView1 = new System.Windows.Forms.ListView(); + this.name = new System.Windows.Forms.ColumnHeader(); + this.owner = new System.Windows.Forms.ColumnHeader(); + this.created = new System.Windows.Forms.ColumnHeader(); + this.updated = new System.Windows.Forms.ColumnHeader(); + this.button1 = new System.Windows.Forms.Button(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.button2 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // listView1 + // + this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.name, + this.owner, + this.created, + this.updated}); + this.listView1.FullRowSelect = true; + this.listView1.Location = new System.Drawing.Point(12, 45); + this.listView1.MultiSelect = false; + this.listView1.Name = "listView1"; + this.listView1.Size = new System.Drawing.Size(546, 429); + this.listView1.TabIndex = 0; + this.listView1.UseCompatibleStateImageBehavior = false; + this.listView1.View = System.Windows.Forms.View.Details; + this.listView1.SelectedIndexChanged += new System.EventHandler(this.on_selected_item_changed); + // + // name + // + this.name.Text = "Name"; + this.name.Width = 150; + // + // owner + // + this.owner.Text = "Owner"; + this.owner.Width = 120; + // + // created + // + this.created.Text = "Created"; + this.created.Width = 100; + // + // updated + // + this.updated.Text = "Updated"; + this.updated.Width = 100; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(483, 16); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 1; + this.button1.Text = "Search"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(12, 16); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(465, 23); + this.textBox1.TabIndex = 2; + // + // button2 + // + this.button2.Location = new System.Drawing.Point(439, 483); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(119, 23); + this.button2.TabIndex = 3; + this.button2.Text = "Add Selected"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // AddNewProjectFromGit + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(570, 518); + this.Controls.Add(this.button2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.button1); + this.Controls.Add(this.listView1); + this.Name = "AddNewProjectFromGit"; + this.Text = "Add new project from Git"; + this.Load += new System.EventHandler(this.AddNewProjectFromGit_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ListView listView1; + private Button button1; + private TextBox textBox1; + private ColumnHeader name; + private ColumnHeader owner; + private ColumnHeader created; + private ColumnHeader updated; + private Button button2; + } +} \ No newline at end of file diff --git a/Titanic/AddNewProjectFromGit.cs b/Titanic/AddNewProjectFromGit.cs new file mode 100644 index 0000000..7fd1f1e --- /dev/null +++ b/Titanic/AddNewProjectFromGit.cs @@ -0,0 +1,101 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Titanic +{ + public partial class AddNewProjectFromGit : Form + { + public AddNewProjectFromGit() + { + InitializeComponent(); + + Refresh(); + } + private void AddNewProjectFromGit_Load(object sender, EventArgs e) + { + + } + + private async void button1_Click(object sender, EventArgs e) + { + string gogsResponse = await Helpers.GetFromGogs("repos/search?q="+textBox1.Text); + Logger.Log(gogsResponse); + dynamic jsonObj = JsonConvert.DeserializeObject(gogsResponse); + Logger.Log(jsonObj.ToString()); + + + listView1.Items.Clear(); + for(int i=0;i < jsonObj.data.Count;i++) + { + dynamic data = jsonObj.data[i]; + + /*foreach(dynamic item in data) { + Logger.Log(item); + }*/ + string name = data.name; + string owner = data.owner.username; + string created = data.created_at; + string updated = data.updated_at; + string clone_uri = data.clone_url; + ListViewItem item = new ListViewItem(); + item.Text = name; + item.SubItems.Add(owner); + item.SubItems.Add(created); + item.SubItems.Add(updated); + item.SubItems.Add(clone_uri); + + listView1.Items.Add(item); + } + + + + //MessageBox.Show(data.name.ToString()); + } + + private void button2_Click(object sender, EventArgs e) + { + string selectedGit = listView1.SelectedItems[0].SubItems[4].Text.Replace("localhost","192.168.1.4"); + MessageBox.Show(selectedGit); + FolderBrowserDialog fbd = new FolderBrowserDialog(); + if(fbd.ShowDialog() == DialogResult.OK ) + { + if(!Directory.Exists(fbd.SelectedPath)) + { + MessageBox.Show("Invalid path"); + return; + } + + string gitClone = Helpers.GetResponseFromCmd($"git clone {selectedGit}", fbd.SelectedPath); + Logger.Log(gitClone); + string projectName = selectedGit.Substring(selectedGit.LastIndexOf('/') + 1).Split(".")[0]; + + Helpers.AddNewProject(new KeyValuePair(projectName, fbd.SelectedPath+"\\"+projectName)); + + } + } + + private void on_selected_item_changed(object sender, EventArgs e) + { + + Refresh(); + } + + + public override void Refresh() + { + base.Refresh(); + + button2.Enabled = listView1.SelectedItems.Count > 0; + + } + } +} diff --git a/Titanic/AddNewProjectFromGit.resx b/Titanic/AddNewProjectFromGit.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Titanic/AddNewProjectFromGit.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Titanic/App.config b/Titanic/App.config new file mode 100644 index 0000000..6e3c343 --- /dev/null +++ b/Titanic/App.config @@ -0,0 +1,18 @@ + + + + +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/Titanic/Form1.Designer.cs b/Titanic/Form1.Designer.cs index 7b9a290..74858df 100644 --- a/Titanic/Form1.Designer.cs +++ b/Titanic/Form1.Designer.cs @@ -30,6 +30,7 @@ { this.listView1 = new System.Windows.Forms.ListView(); this.name = new System.Windows.Forms.ColumnHeader(); + this.path = new System.Windows.Forms.ColumnHeader(); this.last_change = new System.Windows.Forms.ColumnHeader(); this.author = new System.Windows.Forms.ColumnHeader(); this.last_modifier = new System.Windows.Forms.ColumnHeader(); @@ -38,7 +39,7 @@ this.btn_exit = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); - this.path = new System.Windows.Forms.ColumnHeader(); + this.button3 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // listView1 @@ -49,18 +50,30 @@ this.last_change, this.author, this.last_modifier}); + this.listView1.FullRowSelect = true; this.listView1.Location = new System.Drawing.Point(12, 12); + this.listView1.MultiSelect = false; this.listView1.Name = "listView1"; + this.listView1.ShowItemToolTips = true; this.listView1.Size = new System.Drawing.Size(525, 426); this.listView1.TabIndex = 0; + this.listView1.TabStop = false; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.View = System.Windows.Forms.View.Details; + this.listView1.SelectedIndexChanged += new System.EventHandler(this.selected_project_changed); + this.listView1.DoubleClick += new System.EventHandler(this.on_list_view_double_clicked); // // name // this.name.Text = "Project"; this.name.Width = 150; // + // path + // + this.path.Text = "path"; + this.path.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.path.Width = 15; + // // last_change // this.last_change.Text = "Last When"; @@ -78,17 +91,17 @@ // // btn_new_project // - this.btn_new_project.Location = new System.Drawing.Point(543, 108); + this.btn_new_project.Location = new System.Drawing.Point(543, 168); this.btn_new_project.Name = "btn_new_project"; this.btn_new_project.Size = new System.Drawing.Size(156, 23); this.btn_new_project.TabIndex = 1; - this.btn_new_project.Text = "Add New Project"; + this.btn_new_project.Text = "Add from Folder"; this.btn_new_project.UseVisualStyleBackColor = true; this.btn_new_project.Click += new System.EventHandler(this.btn_new_project_Click); // // btn_remove_selected_project // - this.btn_remove_selected_project.Location = new System.Drawing.Point(543, 137); + this.btn_remove_selected_project.Location = new System.Drawing.Point(543, 197); this.btn_remove_selected_project.Name = "btn_remove_selected_project"; this.btn_remove_selected_project.Size = new System.Drawing.Size(156, 23); this.btn_remove_selected_project.TabIndex = 2; @@ -120,23 +133,28 @@ // this.button2.Location = new System.Drawing.Point(543, 65); this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(156, 23); + this.button2.Size = new System.Drawing.Size(156, 37); this.button2.TabIndex = 5; - this.button2.Text = "Info"; + this.button2.Text = "Open"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // - // path + // button3 // - this.path.Text = "path"; - this.path.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - this.path.Width = 15; + this.button3.Location = new System.Drawing.Point(543, 139); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(156, 23); + this.button3.TabIndex = 6; + this.button3.Text = "Add from Git"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(708, 450); + this.Controls.Add(this.button3); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Controls.Add(this.btn_exit); @@ -145,6 +163,7 @@ this.Controls.Add(this.listView1); this.Name = "Form1"; this.Text = "Titanic"; + this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); } @@ -162,5 +181,6 @@ private Button button1; private Button button2; private ColumnHeader path; + private Button button3; } } \ No newline at end of file diff --git a/Titanic/Form1.cs b/Titanic/Form1.cs index f5c4b8c..a582985 100644 --- a/Titanic/Form1.cs +++ b/Titanic/Form1.cs @@ -9,6 +9,7 @@ namespace Titanic settings = Helpers.Settings; Refresh(); + UpdateButtons(); } private void btn_exit_Click(object sender, EventArgs e) @@ -38,13 +39,20 @@ namespace Titanic Dictionary projects = Helpers.Settings.projects; foreach(KeyValuePair project in projects) { + ProjectInfo info = ProjectInfo.FromDirectory(project.Value); ListViewItem item = new ListViewItem(); item.Text = project.Key; item.SubItems.Add(project.Value); + Logger.Log("Listing project " + project.Key + " @ " + project.Value); + if (info.Commits.Count > 0) + { + item.SubItems.Add(info.Commits[0].time.ToShortDateString()); + item.SubItems.Add(info.Commits[info.Commits.Count - 1].Author); + item.SubItems.Add(info.Commits[0].Author); + } listView1.Items.Add(item); - ProjectInfo info = ProjectInfo.FromDirectory(project.Value); } base.Refresh(); @@ -68,6 +76,11 @@ namespace Titanic } private void button2_Click(object sender, EventArgs e) + { + OpenSelected(); + } + + void OpenSelected() { if (listView1.SelectedItems.Count <= 0) { @@ -78,5 +91,50 @@ namespace Titanic ProjectInfoForm projectInfo = new ProjectInfoForm(listView1.SelectedItems[0].SubItems[1].Text); projectInfo.ShowDialog(); } + + private void selected_project_changed(object sender, EventArgs e) + { + UpdateButtons(); + } + + + void UpdateButtons() + { + bool somethingSelected = listView1.SelectedItems.Count == 1; + btn_remove_selected_project.Enabled = button2.Enabled = somethingSelected; + if (somethingSelected) + { + + } + } + + private void on_list_view_double_clicked(object sender, EventArgs e) + { + if(listView1.SelectedItems.Count <= 0) + { + return; + } + + OpenSelected(); + } + + private async void Form1_Load(object sender, EventArgs e) + { + string json = @" +{ + ""name"": ""Hello-World"", + ""description"": ""This is your first repository"", + ""private"": false +} + "; + string create_repo_response = await Helpers.PostAsync(Helpers.GOGS_API + "user/repos",json ); + MessageBox.Show(create_repo_response); + } + + private void button3_Click(object sender, EventArgs e) + { + AddNewProjectFromGit newProjectFromGit = new AddNewProjectFromGit(); + newProjectFromGit.ShowDialog(); + } } } \ No newline at end of file diff --git a/Titanic/Helpers.cs b/Titanic/Helpers.cs index 0dba86b..962ed64 100644 --- a/Titanic/Helpers.cs +++ b/Titanic/Helpers.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; +using System.Net; using System.Text; using System.Threading.Tasks; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; @@ -12,6 +13,7 @@ namespace Titanic { static class Helpers { + public const string GOGS_API = "http://192.168.1.4:3000/api/v1/"; public const string GIT_LOG_CMD = "git log --pretty=format:\"%h%n%ce%n%at%n%s%n\""; private static Settings m_settings; private static string SettingsLocation { get { return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Documents\\Titanic.json"; } } @@ -96,6 +98,7 @@ namespace Titanic Process p = new Process(); // Redirect the output stream of the child process. p.StartInfo.UseShellExecute = false; + p.StartInfo.CreateNoWindow = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.WorkingDirectory = directory; @@ -136,6 +139,125 @@ namespace Titanic return dateTime; } + public static string Get(string uri) + { + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); + request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; + + using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) + using (Stream stream = response.GetResponseStream()) + using (StreamReader reader = new StreamReader(stream)) + { + return reader.ReadToEnd(); + } + } + + public static async Task GetAsync(string uri,string username, string password) + { + HttpClient client = new HttpClient(); + + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri); + HttpResponseMessage response = new HttpResponseMessage(); + try + { + request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes($"{username}:{password}"))); + + response = await client.SendAsync(request); + } + catch(Exception e) + { + MessageBox.Show("NAS not reachable\n"+e.Message); + } + try + { + response.EnsureSuccessStatusCode(); + string responseBody = await response.Content.ReadAsStringAsync(); + return responseBody; + + } + catch + { + return ""; + } + + } + public static async Task PostAsync(string uri,string json, string username=null, string password=null) + { + + if (username == null) { username = Properties.Settings.Default.username; } + if (password == null) { password = Properties.Settings.Default.password; } + + var httpWebRequest = (HttpWebRequest)WebRequest.Create(uri); + httpWebRequest.Credentials = new NetworkCredential(username, password); + httpWebRequest.ContentType = "application/json"; + httpWebRequest.Method = "POST"; + + using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) + { + streamWriter.Write(json); + } + try + { + var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); + using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) + { + var result = streamReader.ReadToEnd(); + } + } + catch + { + Logger.Log($"Failed to retreive response from POST in {uri} as {username}:{password} with {json}"); + } + + + HttpClient client = new HttpClient(); + + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri); + HttpResponseMessage response = new HttpResponseMessage(); + + + return await response.Content.ReadAsStringAsync(); + + } + + + public static async Task GetFromGogs(string path) + { + HttpClient client = new HttpClient(); + string uri = GOGS_API + path; + + string username = Properties.Settings.Default.username; + string password = Properties.Settings.Default.password; + Logger.Log($"Fetching {path} from gogs using {username}:{password}"); + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri); + + request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes($"{username}:{password}"))); + + HttpResponseMessage response = await client.SendAsync(request); + try + { + response.EnsureSuccessStatusCode(); + string responseBody = await response.Content.ReadAsStringAsync(); + return responseBody; + + } + catch + { + return ""; + } + + } + + + public static void OpenURL(string url) + { + System.Diagnostics.Process.Start(new ProcessStartInfo + { + FileName = "explorer", + Arguments = url, + UseShellExecute = false + }); + } } @@ -150,32 +272,63 @@ namespace Titanic { public string Directory; public List Commits; - + public string remote_url; public static ProjectInfo FromDirectory(string directory) { - ProjectInfo info = new ProjectInfo() { Directory = directory }; - string gitLog = Helpers.GetResponseFromCmd(Helpers.GIT_LOG_CMD, directory); - - string actualOutput = Helpers.DeleteLines(gitLog.Substring(gitLog.LastIndexOf(Helpers.GIT_LOG_CMD) + 1), 1); - List commitsList = new List(); - string[] commits = actualOutput.Split(""); - - for (int i = 0; i < commits.Length; i++) + try { - // MessageBox.Show(commits[i]); - string[] commitData = commits[i].Split('\n'); - if (commitData.Length < 5) { continue; } - DateTime time = Helpers.UnixTimeStampToDateTime(double.Parse(commitData[3])); + ProjectInfo info = new ProjectInfo() { Directory = directory }; + string gitLog = Helpers.GetResponseFromCmd(Helpers.GIT_LOG_CMD, directory); - commitsList.Add(new CommitData() { hash = commitData[1], Author = commitData[2], time = time, comments = commitData[4] }); + string actualOutput = Helpers.DeleteLines(gitLog.Substring(gitLog.LastIndexOf(Helpers.GIT_LOG_CMD) + 1), 1); + List commitsList = new List(); + string[] commits = actualOutput.Split(""); + for (int i = 0; i < commits.Length; i++) + { + // MessageBox.Show(commits[i]); + string[] commitData = commits[i].Split('\n'); + if (commitData.Length < 5) { continue; } + DateTime time = Helpers.UnixTimeStampToDateTime(double.Parse(commitData[3])); + + commitsList.Add(new CommitData() { hash = commitData[1], Author = commitData[2], time = time, comments = commitData[4] }); + + } + info.Commits = commitsList; + + if (commits.Length > 0) + { + + + string urlResponse = Helpers.GetResponseFromCmd("git remote show origin", directory); + string url = urlResponse.Substring(urlResponse.IndexOf("Fetch URL:") + 10).Split("\n")[0]; + + if (url.Contains(".git")) + { + //Valid link + info.remote_url = url; + + } + else + { + info.remote_url = "invalid"; + } + + } + else + { + Logger.Log($"Project ${directory}@{info.remote_url} has 0 commits"); + } + return info; + } + catch + { + return null; } - - info.Commits = commitsList; - - return info; } + + } diff --git a/Titanic/Program.cs b/Titanic/Program.cs index e65766a..6155dad 100644 --- a/Titanic/Program.cs +++ b/Titanic/Program.cs @@ -13,7 +13,7 @@ namespace Titanic Logger.Log("Initiating Titanic, Infamous Syncer"); ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new Splash()); } } } \ No newline at end of file diff --git a/Titanic/ProjectInfoForm.Designer.cs b/Titanic/ProjectInfoForm.Designer.cs index 4f0aebe..d32b6db 100644 --- a/Titanic/ProjectInfoForm.Designer.cs +++ b/Titanic/ProjectInfoForm.Designer.cs @@ -33,6 +33,9 @@ this.author = new System.Windows.Forms.ColumnHeader(); this.date = new System.Windows.Forms.ColumnHeader(); this.comment = new System.Windows.Forms.ColumnHeader(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // listView1 @@ -44,7 +47,7 @@ this.comment}); this.listView1.Location = new System.Drawing.Point(12, 12); this.listView1.Name = "listView1"; - this.listView1.Size = new System.Drawing.Size(665, 426); + this.listView1.Size = new System.Drawing.Size(558, 426); this.listView1.TabIndex = 0; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.View = System.Windows.Forms.View.Details; @@ -68,11 +71,44 @@ this.comment.Text = "Comment"; this.comment.Width = 250; // + // button1 + // + this.button1.Location = new System.Drawing.Point(576, 198); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(100, 23); + this.button1.TabIndex = 1; + this.button1.Text = "Revert"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(576, 415); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(100, 23); + this.button2.TabIndex = 2; + this.button2.Text = "Exit"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(576, 12); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(100, 52); + this.button3.TabIndex = 3; + this.button3.Text = "Request Changes"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // // ProjectInfoForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(688, 450); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); this.Controls.Add(this.listView1); this.Name = "ProjectInfoForm"; this.Text = "ProjectInfoForm"; @@ -88,5 +124,8 @@ private ColumnHeader author; private ColumnHeader date; private ColumnHeader comment; + private Button button1; + private Button button2; + private Button button3; } } \ No newline at end of file diff --git a/Titanic/ProjectInfoForm.cs b/Titanic/ProjectInfoForm.cs index 1fe1924..edf128b 100644 --- a/Titanic/ProjectInfoForm.cs +++ b/Titanic/ProjectInfoForm.cs @@ -33,6 +33,7 @@ namespace Titanic listView1.Items.Clear(); ProjectInfo info = ProjectInfo.FromDirectory(directory); + MessageBox.Show(directory + ": " + info.Commits.Count.ToString()); foreach(CommitData commit in info.Commits) { ListViewItem item = new ListViewItem(); @@ -43,6 +44,27 @@ namespace Titanic listView1.Items.Add(item); } + RefreshButtons(); + } + + private void button2_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void button1_Click(object sender, EventArgs e) + { + + } + + + void RefreshButtons() + { + button1.Enabled = listView1.SelectedItems.Count > 0; + } + + private void button3_Click(object sender, EventArgs e) + { } } diff --git a/Titanic/Properties/Settings.Designer.cs b/Titanic/Properties/Settings.Designer.cs new file mode 100644 index 0000000..f4a4f3e --- /dev/null +++ b/Titanic/Properties/Settings.Designer.cs @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Titanic.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.4.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string username { + get { + return ((string)(this["username"])); + } + set { + this["username"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string password { + get { + return ((string)(this["password"])); + } + set { + this["password"] = value; + } + } + } +} diff --git a/Titanic/Properties/Settings.settings b/Titanic/Properties/Settings.settings new file mode 100644 index 0000000..3a23e00 --- /dev/null +++ b/Titanic/Properties/Settings.settings @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Titanic/Splash.Designer.cs b/Titanic/Splash.Designer.cs new file mode 100644 index 0000000..016741d --- /dev/null +++ b/Titanic/Splash.Designer.cs @@ -0,0 +1,162 @@ +namespace Titanic +{ + partial class Splash + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.btn_login = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Segoe UI", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0))))); + this.label1.Location = new System.Drawing.Point(305, 126); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(153, 37); + this.label1.TabIndex = 0; + this.label1.Text = "Gogs Login"; + // + // textBox1 + // + this.textBox1.BackColor = System.Drawing.Color.Gray; + this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.textBox1.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.textBox1.ForeColor = System.Drawing.Color.White; + this.textBox1.Location = new System.Drawing.Point(208, 202); + this.textBox1.Margin = new System.Windows.Forms.Padding(10, 3, 3, 3); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(354, 22); + this.textBox1.TabIndex = 1; + // + // textBox2 + // + this.textBox2.BackColor = System.Drawing.Color.Gray; + this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.textBox2.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.textBox2.ForeColor = System.Drawing.Color.White; + this.textBox2.Location = new System.Drawing.Point(208, 231); + this.textBox2.Margin = new System.Windows.Forms.Padding(10, 3, 3, 3); + this.textBox2.Name = "textBox2"; + this.textBox2.PasswordChar = '*'; + this.textBox2.Size = new System.Drawing.Size(354, 22); + this.textBox2.TabIndex = 2; + // + // btn_login + // + this.btn_login.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); + this.btn_login.FlatAppearance.BorderSize = 0; + this.btn_login.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btn_login.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.btn_login.ForeColor = System.Drawing.Color.White; + this.btn_login.Location = new System.Drawing.Point(305, 288); + this.btn_login.Name = "btn_login"; + this.btn_login.Size = new System.Drawing.Size(166, 34); + this.btn_login.TabIndex = 3; + this.btn_login.Text = "Login"; + this.btn_login.UseVisualStyleBackColor = false; + this.btn_login.Click += new System.EventHandler(this.btn_login_ClickAsync); + // + // button2 + // + this.button2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); + this.button2.FlatAppearance.BorderSize = 0; + this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.button2.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.button2.ForeColor = System.Drawing.Color.White; + this.button2.Location = new System.Drawing.Point(335, 360); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(106, 34); + this.button2.TabIndex = 4; + this.button2.Text = "Close"; + this.button2.UseVisualStyleBackColor = false; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Segoe UI", 22F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label2.ForeColor = System.Drawing.Color.Gray; + this.label2.Location = new System.Drawing.Point(250, 36); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(261, 41); + this.label2.TabIndex = 5; + this.label2.Text = "360 Project Syncer"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255))))); + this.label3.Location = new System.Drawing.Point(582, 420); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(190, 15); + this.label3.TabIndex = 6; + this.label3.Text = "No Account? Click here to Register"; + this.label3.Click += new System.EventHandler(this.label3_Click); + // + // Splash + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20))))); + this.ClientSize = new System.Drawing.Size(784, 444); + this.ControlBox = false; + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.button2); + this.Controls.Add(this.btn_login); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "Splash"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Splash"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private TextBox textBox1; + private TextBox textBox2; + private Button btn_login; + private Button button2; + private Label label2; + private Label label3; + } +} \ No newline at end of file diff --git a/Titanic/Splash.cs b/Titanic/Splash.cs new file mode 100644 index 0000000..30359f5 --- /dev/null +++ b/Titanic/Splash.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Net; +using System.Security.Policy; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Titanic +{ + public partial class Splash : Form + { + public Splash() + { + InitializeComponent(); + + if(Properties.Settings.Default.username.Length >0 && Properties.Settings.Default.password.Length > 0) + { + textBox1.Text = Properties.Settings.Default.username; + textBox2.Text = Properties.Settings.Default.password; + + //Login(); + } + } + + private void label3_Click(object sender, EventArgs e) + { + Helpers.OpenURL("http://192.168.1.4:3000/user/sign_up"); + } + + private void btn_login_ClickAsync(object sender, EventArgs e) + { + Login(); + } + + async void Login() + { + this.Hide(); + string curlArgs = $"-u {textBox1.Text}:{textBox2.Text} {Helpers.GOGS_API}users/{textBox1.Text}/tokens"; + string uri = $"{Helpers.GOGS_API}users/{textBox1.Text}/tokens"; + + + string loginResponse = await Helpers.GetAsync(uri, textBox1.Text, textBox2.Text); + try + { + + //string loginResponse = Helpers.Get(Helpers.GOGS_API + "users/" + textBox1.Text + "/tokens"); + if (loginResponse.Contains("[") && loginResponse.Contains("]")) + { + //MessageBox.Show("Success\n"+loginResponse.Split("[")[0].Split("]")[0]); + OnLoginSuccess(); + return; + } + } + catch (Exception ex) + { + MessageBox.Show(loginResponse); + } + + this.Show(); + } + + void OnLoginSuccess() + { + Properties.Settings.Default.username = textBox1.Text; + Properties.Settings.Default.password= textBox2.Text; + Properties.Settings.Default.Save(); + + this.Hide(); + + Form1 form = new Form1(); + form.Show(); + } + + private void button2_Click(object sender, EventArgs e) + { + Application.Exit(); + } + } +} diff --git a/Titanic/Splash.resx b/Titanic/Splash.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Titanic/Splash.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Titanic/Titanic.csproj b/Titanic/Titanic.csproj index 6bf2ac4..069eeda 100644 --- a/Titanic/Titanic.csproj +++ b/Titanic/Titanic.csproj @@ -12,4 +12,19 @@ + + + True + True + Settings.settings + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + \ No newline at end of file diff --git a/Titanic/Titanic.csproj.user b/Titanic/Titanic.csproj.user index bf3fe5c..2296b22 100644 --- a/Titanic/Titanic.csproj.user +++ b/Titanic/Titanic.csproj.user @@ -1,6 +1,9 @@  + + Form + Form @@ -10,5 +13,8 @@ Form + + Form + \ No newline at end of file diff --git a/Titanic/bin/Debug/net6.0-windows/Log.txt b/Titanic/bin/Debug/net6.0-windows/Log.txt index a7b1ab2..f069639 100644 --- a/Titanic/bin/Debug/net6.0-windows/Log.txt +++ b/Titanic/bin/Debug/net6.0-windows/Log.txt @@ -1,5 +1,13 @@ -Logger initiated at 1/31/2023 7:25:47 PM +Logger initiated at 2/1/2023 11:45:37 PM -[1/31/2023 7:25:47 PM] Initiating Titanic, Infamous Syncer -[1/31/2023 7:25:47 PM] Reading settings from file success -[1/31/2023 7:25:47 PM] Reading settings from file success +[2/1/2023 11:45:37 PM] Initiating Titanic, Infamous Syncer +[2/1/2023 11:45:39 PM] Reading settings from file success +[2/1/2023 11:45:39 PM] Reading settings from file success +[2/1/2023 11:45:40 PM] Listing project test @ C:\Users\warlock\Documents\Temp\git_test\2\2\test\2\test +[2/1/2023 11:45:40 PM] Failed to retreive response from POST in http://192.168.1.4:3000/api/v1/warlock/repos as warlock:HelloWorld with +{ + "name": "Hello-World", + "description": "This is your first repository", + "private": false +} + diff --git a/Titanic/bin/Debug/net6.0-windows/Titanic.dll b/Titanic/bin/Debug/net6.0-windows/Titanic.dll index 098f386..e1811b1 100644 Binary files a/Titanic/bin/Debug/net6.0-windows/Titanic.dll and b/Titanic/bin/Debug/net6.0-windows/Titanic.dll differ diff --git a/Titanic/bin/Debug/net6.0-windows/Titanic.dll.config b/Titanic/bin/Debug/net6.0-windows/Titanic.dll.config new file mode 100644 index 0000000..6e3c343 --- /dev/null +++ b/Titanic/bin/Debug/net6.0-windows/Titanic.dll.config @@ -0,0 +1,18 @@ + + + + +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/Titanic/bin/Debug/net6.0-windows/Titanic.pdb b/Titanic/bin/Debug/net6.0-windows/Titanic.pdb index 258c381..2c7041b 100644 Binary files a/Titanic/bin/Debug/net6.0-windows/Titanic.pdb and b/Titanic/bin/Debug/net6.0-windows/Titanic.pdb differ diff --git a/Titanic/new_project_form.Designer.cs b/Titanic/new_project_form.Designer.cs index 7d66fe3..7c1a5bd 100644 --- a/Titanic/new_project_form.Designer.cs +++ b/Titanic/new_project_form.Designer.cs @@ -30,11 +30,13 @@ { this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); - this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); + this.lbl_name = new System.Windows.Forms.Label(); + this.lbl_status = new System.Windows.Forms.Label(); this.SuspendLayout(); // // label1 @@ -42,9 +44,9 @@ this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(12, 75); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(79, 15); + this.label1.Size = new System.Drawing.Size(85, 15); this.label1.TabIndex = 0; - this.label1.Text = "Project Name"; + this.label1.Text = "Project Name :"; // // label2 // @@ -55,13 +57,6 @@ this.label2.TabIndex = 1; this.label2.Text = "Directory"; // - // textBox1 - // - this.textBox1.Location = new System.Drawing.Point(99, 72); - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(359, 23); - this.textBox1.TabIndex = 2; - // // textBox2 // this.textBox2.Location = new System.Drawing.Point(99, 17); @@ -81,7 +76,7 @@ // // button2 // - this.button2.Location = new System.Drawing.Point(302, 101); + this.button2.Location = new System.Drawing.Point(302, 184); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); this.button2.TabIndex = 5; @@ -91,7 +86,7 @@ // // button3 // - this.button3.Location = new System.Drawing.Point(383, 101); + this.button3.Location = new System.Drawing.Point(383, 184); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(75, 23); this.button3.TabIndex = 6; @@ -99,22 +94,53 @@ this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(33, 100); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(63, 15); + this.label3.TabIndex = 7; + this.label3.Text = "Git Status :"; + // + // lbl_name + // + this.lbl_name.AutoSize = true; + this.lbl_name.Location = new System.Drawing.Point(102, 76); + this.lbl_name.Name = "lbl_name"; + this.lbl_name.Size = new System.Drawing.Size(16, 15); + this.lbl_name.TabIndex = 8; + this.lbl_name.Text = "..."; + // + // lbl_status + // + this.lbl_status.AutoSize = true; + this.lbl_status.Location = new System.Drawing.Point(102, 100); + this.lbl_status.Name = "lbl_status"; + this.lbl_status.Size = new System.Drawing.Size(16, 15); + this.lbl_status.TabIndex = 9; + this.lbl_status.Text = "..."; + this.lbl_status.Click += new System.EventHandler(this.lbl_status_Click); + // // new_project_form // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(470, 131); + this.ClientSize = new System.Drawing.Size(470, 214); + this.Controls.Add(this.lbl_status); + this.Controls.Add(this.lbl_name); + this.Controls.Add(this.label3); this.Controls.Add(this.button3); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Controls.Add(this.textBox2); - this.Controls.Add(this.textBox1); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "new_project_form"; this.Text = "New Project"; + this.Load += new System.EventHandler(this.new_project_form_Load); this.ResumeLayout(false); this.PerformLayout(); @@ -124,10 +150,12 @@ private Label label1; private Label label2; - private TextBox textBox1; private TextBox textBox2; private Button button1; private Button button2; private Button button3; + private Label label3; + private Label lbl_name; + private Label lbl_status; } } \ No newline at end of file diff --git a/Titanic/new_project_form.cs b/Titanic/new_project_form.cs index 841e386..2766bf0 100644 --- a/Titanic/new_project_form.cs +++ b/Titanic/new_project_form.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.Drawing; using System.Linq; +using System.Security.Policy; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -26,28 +28,81 @@ namespace Titanic private void button2_Click(object sender, EventArgs e) { - if(textBox1.Text.Length < 3) + if(lbl_name.Text.Length < 2) { MessageBox.Show("Project name must be longer than 2 letters"); return; } if (!Directory.Exists(textBox2.Text)) { - MessageBox.Show("Invalid git link"); + MessageBox.Show("Invalid path"); return; } + if (!gitInit) + { + string initCmd = Helpers.GetResponseFromCmd("git init", textBox2.Text); + //MessageBox.Show("Git initiated on " + initCmd); + string initCommit = Helpers.GetResponseFromCmd("git add . && git commit -m 'Init'", textBox2.Text); + //MessageBox.Show("Commited first commit"); + - OnSuccess.Invoke(new KeyValuePair(textBox1.Text, textBox2.Text)); + //TODO: Create repo here + } + OnSuccess.Invoke(new KeyValuePair(lbl_name.Text, textBox2.Text)); this.Close(); } - + bool gitInit = false; private void button1_Click(object sender, EventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); if(fbd.ShowDialog() == DialogResult.OK) { - textBox2.Text= fbd.SelectedPath; - textBox1.Text = fbd.SelectedPath.Substring(fbd.SelectedPath.LastIndexOf("\\")+1); + textBox2.Text = fbd.SelectedPath; + lbl_name.Text = fbd.SelectedPath.Substring(fbd.SelectedPath.LastIndexOf("\\")+1); + + + ProjectInfo info = ProjectInfo.FromDirectory(textBox2.Text); + if (info == null) + { + lbl_status.Text = "Git is not initiated"; + } + else + { + if (info.Commits.Count <= 0) + { + lbl_status.Text = "Git is not initiated"; + gitInit = false; + } + else + { + gitInit = true; + lbl_status.Text = $"Git found with {info.Commits.Count} commits from {info.Commits[0].Author}\nLast Updated : {info.Commits[0].time.ToString()}"; + lbl_status.Text += $"\nurl: {info.remote_url}"; + + selectedURL = info.remote_url; + if (info.remote_url == "invalid") + { + this.Close(); + MessageBox.Show("Invalid remote link. Fix the remote address before continuing"); + + } + } + + } + } + } + + private void new_project_form_Load(object sender, EventArgs e) + { + + } + string selectedURL; + private void lbl_status_Click(object sender, EventArgs e) + { + if (selectedURL != null) + { + Helpers.OpenURL(selectedURL); + } } } diff --git a/Titanic/obj/Debug/net6.0-windows/Titanic.AddNewProjectFromGit.resources b/Titanic/obj/Debug/net6.0-windows/Titanic.AddNewProjectFromGit.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/Titanic/obj/Debug/net6.0-windows/Titanic.AddNewProjectFromGit.resources differ diff --git a/Titanic/obj/Debug/net6.0-windows/Titanic.Splash.resources b/Titanic/obj/Debug/net6.0-windows/Titanic.Splash.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/Titanic/obj/Debug/net6.0-windows/Titanic.Splash.resources differ diff --git a/Titanic/obj/Debug/net6.0-windows/Titanic.csproj.CoreCompileInputs.cache b/Titanic/obj/Debug/net6.0-windows/Titanic.csproj.CoreCompileInputs.cache index fe8bdb4..347791e 100644 --- a/Titanic/obj/Debug/net6.0-windows/Titanic.csproj.CoreCompileInputs.cache +++ b/Titanic/obj/Debug/net6.0-windows/Titanic.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -df9c89a8c95990cc221e7d13453b50470fc9fac4 +7a75a2636ec233f7d2a889543d745cae42d790b8 diff --git a/Titanic/obj/Debug/net6.0-windows/Titanic.csproj.FileListAbsolute.txt b/Titanic/obj/Debug/net6.0-windows/Titanic.csproj.FileListAbsolute.txt index f8c33d1..fadede7 100644 --- a/Titanic/obj/Debug/net6.0-windows/Titanic.csproj.FileListAbsolute.txt +++ b/Titanic/obj/Debug/net6.0-windows/Titanic.csproj.FileListAbsolute.txt @@ -19,3 +19,6 @@ D:\Project\c#\shared\Titanic\Titanic\obj\Debug\net6.0-windows\Titanic.pdb D:\Project\c#\shared\Titanic\Titanic\obj\Debug\net6.0-windows\Titanic.genruntimeconfig.cache D:\Project\c#\shared\Titanic\Titanic\obj\Debug\net6.0-windows\ref\Titanic.dll D:\Project\c#\shared\Titanic\Titanic\obj\Debug\net6.0-windows\Titanic.ProjectInfoForm.resources +D:\Project\c#\shared\Titanic\Titanic\obj\Debug\net6.0-windows\Titanic.Splash.resources +D:\Project\c#\shared\Titanic\Titanic\bin\Debug\net6.0-windows\Titanic.dll.config +D:\Project\c#\shared\Titanic\Titanic\obj\Debug\net6.0-windows\Titanic.AddNewProjectFromGit.resources diff --git a/Titanic/obj/Debug/net6.0-windows/Titanic.csproj.GenerateResource.cache b/Titanic/obj/Debug/net6.0-windows/Titanic.csproj.GenerateResource.cache index 9b9edfc..64c013a 100644 Binary files a/Titanic/obj/Debug/net6.0-windows/Titanic.csproj.GenerateResource.cache and b/Titanic/obj/Debug/net6.0-windows/Titanic.csproj.GenerateResource.cache differ diff --git a/Titanic/obj/Debug/net6.0-windows/Titanic.dll b/Titanic/obj/Debug/net6.0-windows/Titanic.dll index 098f386..e1811b1 100644 Binary files a/Titanic/obj/Debug/net6.0-windows/Titanic.dll and b/Titanic/obj/Debug/net6.0-windows/Titanic.dll differ diff --git a/Titanic/obj/Debug/net6.0-windows/Titanic.pdb b/Titanic/obj/Debug/net6.0-windows/Titanic.pdb index 258c381..2c7041b 100644 Binary files a/Titanic/obj/Debug/net6.0-windows/Titanic.pdb and b/Titanic/obj/Debug/net6.0-windows/Titanic.pdb differ diff --git a/Titanic/obj/Debug/net6.0-windows/ref/Titanic.dll b/Titanic/obj/Debug/net6.0-windows/ref/Titanic.dll index 4b09655..dc25bf8 100644 Binary files a/Titanic/obj/Debug/net6.0-windows/ref/Titanic.dll and b/Titanic/obj/Debug/net6.0-windows/ref/Titanic.dll differ diff --git a/Titanic/obj/Debug/net6.0-windows/refint/Titanic.dll b/Titanic/obj/Debug/net6.0-windows/refint/Titanic.dll index 4b09655..dc25bf8 100644 Binary files a/Titanic/obj/Debug/net6.0-windows/refint/Titanic.dll and b/Titanic/obj/Debug/net6.0-windows/refint/Titanic.dll differ