5
5
using System . Net ;
6
6
using Renci . SshNet ;
7
7
using Renci . SshNet . Sftp ;
8
+ using System . Diagnostics ;
8
9
9
10
namespace Send_And_Delete
10
11
{
@@ -13,6 +14,31 @@ public partial class Main : Form
13
14
public Main ( )
14
15
{
15
16
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
+ }
16
42
}
17
43
18
44
private string SelectFolder ( ) //폴더 선택
@@ -32,6 +58,7 @@ private void TextBox_path_Click(object sender, EventArgs e)
32
58
Properties . Settings . Default . Path = TextBox_path . Text ;
33
59
Properties . Settings . Default . Save ( ) ;
34
60
}
61
+ else MessageBox . Show ( "SAD가 폴더를 감시중입니다.\n 감시를 해제한 후 다시 눌러보세요!" , "파란대나무숲 SAD :(" , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
35
62
}
36
63
37
64
private void Main_Load ( object sender , EventArgs e )
@@ -48,7 +75,7 @@ private void Main_Load(object sender, EventArgs e)
48
75
Tray . Visible = true ;
49
76
}
50
77
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 ;
52
79
ListBox ( $ "[SAD] 현재 설정") ;
53
80
ListBox ( $ " 설정 폴더 : { TextBox_path . Text } ") ;
54
81
ListBox ( $ " 윈도우 시작시 자동 실행 : { WindowsRun . Checked } ") ;
@@ -57,6 +84,7 @@ private void Main_Load(object sender, EventArgs e)
57
84
ListBox ( $ " 업로드 후 삭제 : { Autodelete . Checked } ") ;
58
85
ListBox ( $ " 업로드 URL : { TextBox_URL . Text } ") ;
59
86
if ( AutoStart . Checked ) RunSet ( ) ;
87
+ Upload ( "" , "" ) ;
60
88
}
61
89
62
90
private void Tray_Click ( object sender , EventArgs e )
@@ -79,7 +107,6 @@ private void RunSet()
79
107
if ( Run == true )
80
108
{
81
109
FileWatcher ( ) ;
82
- this . Text = "SAD(전송 및 삭제, Send And Delete) 감시중" ;
83
110
}
84
111
else
85
112
{
@@ -99,41 +126,52 @@ private void Upload(string name, string link)
99
126
try
100
127
{
101
128
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 ;
107
132
}
108
133
catch ( Exception )
109
134
{
110
135
ipf = true ; //실패시 폴더가 이미 있는 것으로 간주
136
+ return ;
111
137
}
112
138
}
113
139
using ( var infile = File . Open ( link , FileMode . Open ) )
114
140
{
115
141
sftp . UploadFile ( infile , $ "/upload/{ IP } /{ name } ") ; //업로드
116
142
}
117
143
sftp . Disconnect ( ) ;
118
- ListBox ( $ "[SAD] 업로드 완료 : { TextBox_URL . Text } /{ name } ") ;
144
+ if ( name != "index.php" ) ListBox ( $ "[SAD] 업로드 완료 : { TextBox_URL . Text } /{ name } ") ;
119
145
if ( Autodelete . Checked ) File . Delete ( link ) ; //자동삭제 체크시 삭제
120
146
}
121
147
122
148
private void FileWatcher ( )
123
149
{
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 )
125
168
{
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 ;
135
174
}
136
- watcher . EnableRaisingEvents = true ;
137
175
}
138
176
139
177
private void Event ( object source , FileSystemEventArgs e )
@@ -236,6 +274,13 @@ private void Main_Move(object sender, EventArgs e)
236
274
}
237
275
}
238
276
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
+
239
284
// 등록된 프로그램 제거
240
285
public void RemoveStartupProgram ( string programName )
241
286
{
0 commit comments