Skip to content

Commit f1f080b

Browse files
committed
feat. Prevent duplicate execution, automatic updates, installers
Warns you when running duplicates. Check and update the version when the program starts. Provides an installer. 중복 실행시 경고를 띄웁니다. 프로그램 시작시 버전 확인 후 업데이트합니다. 인스톨러를 제공합니다.
1 parent d2f881c commit f1f080b

34 files changed

+2723
-382
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
custom: ["https://paypal.me/sh4cker", "https://toon.at/donate/sh4cker"]

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*.user
1010
*.userosscache
1111
*.sln.docstates
12+
*.ico
1213

1314
# User-specific files (MonoDevelop/Xamarin Studio)
1415
*.userprefs

Main.Designer.cs

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Main.cs

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Net;
66
using Renci.SshNet;
77
using Renci.SshNet.Sftp;
8+
using System.Diagnostics;
89

910
namespace Send_And_Delete
1011
{
@@ -13,6 +14,31 @@ public partial class Main : Form
1314
public Main()
1415
{
1516
InitializeComponent();
17+
this.MaximizeBox = false;
18+
19+
//중복실행방지
20+
System.Diagnostics.Process[] processes = null;
21+
string CurrentProcess = System.Diagnostics.Process.GetCurrentProcess().ProcessName.ToUpper();
22+
processes = System.Diagnostics.Process.GetProcessesByName(CurrentProcess);
23+
if (processes.Length > 1)
24+
{
25+
MessageBox.Show("이미 SAD가 실행중입니다.\n작업표시줄 오른쪽 아이콘을 확인해보세요!", "파란대나무숲 SAD :(", MessageBoxButtons.OK, MessageBoxIcon.Error);
26+
//Application.Exit();
27+
Environment.Exit(0);
28+
}
29+
WebClient wc = new WebClient();
30+
string new_ver = wc.DownloadString("http://sad.bbforest.net/ver.txt");
31+
ver.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
32+
if (ver.Text != new_ver)
33+
{
34+
DialogResult result = MessageBox.Show("업데이트가 있습니다! 업데이트 할까요?", "파란대나무숲 SAD :(", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
35+
if (result == DialogResult.Yes)
36+
{
37+
wc.DownloadFile("http://sad.bbforest.net/sad.msi", Environment.GetEnvironmentVariable("temp") + "\\sad.msi");
38+
Process.Start(Environment.GetEnvironmentVariable("temp") + "\\sad.msi");
39+
Environment.Exit(0);
40+
}
41+
}
1642
}
1743

1844
private string SelectFolder() //폴더 선택
@@ -32,6 +58,7 @@ private void TextBox_path_Click(object sender, EventArgs e)
3258
Properties.Settings.Default.Path = TextBox_path.Text;
3359
Properties.Settings.Default.Save();
3460
}
61+
else MessageBox.Show("SAD가 폴더를 감시중입니다.\n감시를 해제한 후 다시 눌러보세요!", "파란대나무숲 SAD :(", MessageBoxButtons.OK, MessageBoxIcon.Warning);
3562
}
3663

3764
private void Main_Load(object sender, EventArgs e)
@@ -48,7 +75,7 @@ private void Main_Load(object sender, EventArgs e)
4875
Tray.Visible = true;
4976
}
5077
IP = new WebClient().DownloadString("http://ipinfo.io/ip").Trim();
51-
TextBox_URL.Text = "http://sad.bbforest.net/" + IP;
78+
TextBox_URL.Text = "http://sad.bbforest.net?dir=" + IP;
5279
ListBox($"[SAD] 현재 설정");
5380
ListBox($" 설정 폴더 : {TextBox_path.Text}");
5481
ListBox($" 윈도우 시작시 자동 실행 : {WindowsRun.Checked}");
@@ -57,6 +84,7 @@ private void Main_Load(object sender, EventArgs e)
5784
ListBox($" 업로드 후 삭제 : {Autodelete.Checked}");
5885
ListBox($" 업로드 URL : {TextBox_URL.Text}");
5986
if (AutoStart.Checked) RunSet();
87+
Upload("","");
6088
}
6189

6290
private void Tray_Click(object sender, EventArgs e)
@@ -79,7 +107,6 @@ private void RunSet()
79107
if (Run == true)
80108
{
81109
FileWatcher();
82-
this.Text = "SAD(전송 및 삭제, Send And Delete) 감시중";
83110
}
84111
else
85112
{
@@ -99,41 +126,52 @@ private void Upload(string name, string link)
99126
try
100127
{
101128
sftp.CreateDirectory($"/upload/{IP}"); //폴더 생성 시도
102-
using (var outfile = File.Create("index.html"))
103-
{
104-
sftp.DownloadFile("/upload/gal.html", outfile);
105-
sftp.UploadFile(outfile, $"/upload/{IP}/index.html");
106-
}
129+
ListBox($"[SAD] 서버에 폴더 생성");
130+
ipf = true;
131+
return;
107132
}
108133
catch (Exception)
109134
{
110135
ipf = true; //실패시 폴더가 이미 있는 것으로 간주
136+
return;
111137
}
112138
}
113139
using (var infile = File.Open(link, FileMode.Open))
114140
{
115141
sftp.UploadFile(infile, $"/upload/{IP}/{name}"); //업로드
116142
}
117143
sftp.Disconnect();
118-
ListBox($"[SAD] 업로드 완료 : {TextBox_URL.Text}/{name}");
144+
if (name != "index.php") ListBox($"[SAD] 업로드 완료 : {TextBox_URL.Text}/{name}");
119145
if(Autodelete.Checked) File.Delete(link); //자동삭제 체크시 삭제
120146
}
121147

122148
private void FileWatcher()
123149
{
124-
if (setup == false)
150+
try
151+
{
152+
if (setup == false)
153+
{
154+
setup = true;
155+
watcher.Path = Properties.Settings.Default.Path;
156+
watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size;
157+
watcher.Filter = "*.*";
158+
watcher.IncludeSubdirectories = true;
159+
watcher.Created += new FileSystemEventHandler(Event);
160+
//watcher.Changed += new FileSystemEventHandler(Event);
161+
watcher.Deleted += new FileSystemEventHandler(Event);
162+
watcher.Renamed += new RenamedEventHandler(Rename);
163+
}
164+
watcher.EnableRaisingEvents = true;
165+
this.Text = "SAD(전송 및 삭제, Send And Delete) 감시중";
166+
}
167+
catch (Exception)
125168
{
126-
setup = true;
127-
watcher.Path = Properties.Settings.Default.Path;
128-
watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size;
129-
watcher.Filter = "*.*";
130-
watcher.IncludeSubdirectories = true;
131-
watcher.Created += new FileSystemEventHandler(Event);
132-
watcher.Changed += new FileSystemEventHandler(Event);
133-
watcher.Deleted += new FileSystemEventHandler(Event);
134-
watcher.Renamed += new RenamedEventHandler(Rename);
169+
MessageBox.Show("폴더를 못 찾았어요. :(\n올바른 폴더를 지정해주세요.", "파란대나무숲 SAD :(", MessageBoxButtons.OK, MessageBoxIcon.Error);
170+
Run = false;
171+
ListBox($"[SAD] 감시 상태 : {Run}");
172+
this.Text = "SAD(전송 및 삭제, Send And Delete)";
173+
watcher.EnableRaisingEvents = false;
135174
}
136-
watcher.EnableRaisingEvents = true;
137175
}
138176

139177
private void Event(object source, FileSystemEventArgs e)
@@ -236,6 +274,13 @@ private void Main_Move(object sender, EventArgs e)
236274
}
237275
}
238276

277+
private void Main_FormClosing(object sender, FormClosingEventArgs e)
278+
{
279+
DialogResult result = MessageBox.Show("프로그램을 종료할까요?\n최소화를 누르면 트레이에서 동작해요!", "파란대나무숲 SAD :(", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
280+
if (result == DialogResult.Yes) Environment.Exit(0);
281+
else e.Cancel = true;
282+
}
283+
239284
// 등록된 프로그램 제거
240285
public void RemoveStartupProgram(string programName)
241286
{

0 commit comments

Comments
 (0)