@@ -71,18 +71,18 @@ private async void OnChanged(object source, FileSystemEventArgs e)
7171 Write = true ;
7272 if ( type is CodeType . Web )
7373 {
74- obj1 . Code = CodeSave . Load ( Local + e . Name ) ;
74+ obj3 . Codes [ e . Name ] = CodeSave . Load ( Local + e . Name ) . Replace ( " \r " , "" ) ;
7575 await Dispatcher . InvokeAsync ( ( ) =>
7676 {
77- Model = App . StartContrast ( obj1 , old ) ;
78- textEditor . Text = obj1 . Code ;
77+ Model = App . StartContrast ( type , obj3 . UUID , obj3 . Codes [ e . Name ] , old ) ;
78+ textEditor . Text = obj3 . Codes [ e . Name ] ;
7979 } ) ;
8080 }
8181 else if ( type is not CodeType . App and not CodeType . Web )
8282 {
8383 if ( e . Name == "main.cs" )
8484 {
85- obj1 . Code = CodeSave . Load ( Local + "main.cs" ) ;
85+ obj1 . Code = CodeSave . Load ( Local + "main.cs" ) . Replace ( " \r " , "" ) ;
8686 await Dispatcher . InvokeAsync ( ( ) =>
8787 {
8888 Model = App . StartContrast ( obj1 , old ) ;
@@ -114,18 +114,22 @@ public async void GetCode()
114114 else
115115 obj1 = data ;
116116
117+ obj1 . Code = obj1 . Code ;
118+
117119 textEditor . Text = obj1 . Code ;
118120 old = obj1 . Code ;
119121 Text . Text = obj1 . Text ;
120122 if ( File . Exists ( Local + "main.cs" ) )
121123 {
122124 string time = string . Format ( "{0:s}" , DateTime . Now ) . Replace ( ":" , "_" ) ;
123- var newLocal = Local + "backup/" ;
124- if ( ! Directory . Exists ( newLocal ) )
125+ try
126+ {
127+ ZIPUtils . Pack ( Local , Local + "main.cs" , time + ".cs" ) ;
128+ }
129+ catch
125130 {
126- Directory . CreateDirectory ( newLocal ) ;
131+ MessageBox . Show ( "备份失败" ) ;
127132 }
128- File . Move ( Local + "main.cs" , newLocal + time + ".cs" ) ;
129133 }
130134 CodeSave . Save ( Local + "main.cs" , obj1 . Code ) ;
131135 App . LogShow ( "获取代码" , $ "代码{ obj1 . Type } [{ obj1 . UUID } ]获取成功") ;
@@ -145,11 +149,13 @@ public async void GetCode()
145149 FileList . Items . Clear ( ) ;
146150
147151 string time = string . Format ( "{0:s}" , DateTime . Now ) . Replace ( ":" , "_" ) ;
148- var newLocal = Local + $ "backup_{ time } /";
149- if ( ! Directory . Exists ( newLocal ) )
152+
153+ var newLocal = Local + $ "backup/";
154+ if ( Directory . Exists ( newLocal ) )
150155 {
151- Directory . CreateDirectory ( newLocal ) ;
156+ Directory . Delete ( newLocal , true ) ;
152157 }
158+ Directory . CreateDirectory ( newLocal ) ;
153159
154160 foreach ( var item in obj3 . Codes )
155161 {
@@ -160,6 +166,17 @@ public async void GetCode()
160166 CodeSave . Save ( Local + item . Key , item . Value ) ;
161167 FileList . Items . Add ( item . Key ) ;
162168 }
169+
170+ try
171+ {
172+ ZIPUtils . Pack1 ( Local , newLocal , $ "backup_{ time } ") ;
173+ }
174+ catch
175+ {
176+ MessageBox . Show ( "备份失败" ) ;
177+ }
178+ Directory . Delete ( newLocal , true ) ;
179+
163180 foreach ( var item in obj3 . Files )
164181 {
165182 FileList . Items . Add ( item . Key ) ;
@@ -244,13 +261,13 @@ private async Task UpdateTask()
244261 if ( thisfile . EndsWith ( ".cs" ) )
245262 {
246263 string temp = thisfile . Replace ( ".cs" , "" ) ;
247- obj2 . Codes [ temp ] = textEditor . Text ;
264+ obj2 . Codes [ temp ] = textEditor . Text . Replace ( " \r " , "" ) ;
248265 Model = App . StartContrast ( type , obj2 . UUID , obj2 . Codes [ temp ] , old ) ;
249266 }
250267 else if ( thisfile . EndsWith ( ".xaml" ) )
251268 {
252269 string temp = thisfile . Replace ( ".xaml" , "" ) ;
253- obj2 . Codes [ temp ] = textEditor . Text ;
270+ obj2 . Codes [ temp ] = textEditor . Text . Replace ( " \r " , "" ) ;
254271 Model = App . StartContrast ( type , obj2 . UUID , obj2 . Xamls [ temp ] , old ) ;
255272 }
256273 else
@@ -265,7 +282,7 @@ private async Task UpdateTask()
265282 || thisfile . EndsWith ( ".js" ) || thisfile . EndsWith ( ".json" )
266283 || thisfile . EndsWith ( ".txt" ) )
267284 {
268- obj3 . Codes [ thisfile ] = textEditor . Text ;
285+ obj3 . Codes [ thisfile ] = textEditor . Text . Replace ( " \r " , "" ) ;
269286 Model = App . StartContrast ( type , obj3 . UUID , obj3 . Codes [ thisfile ] , old ) ;
270287 }
271288 else
@@ -276,7 +293,7 @@ private async Task UpdateTask()
276293 else
277294 {
278295 obj1 . Text = Text . Text ;
279- obj1 . Code = textEditor . Text ;
296+ obj1 . Code = textEditor . Text . Replace ( " \r " , "" ) ;
280297 await Dispatcher . InvokeAsync ( ( ) =>
281298 {
282299 Model = App . StartContrast ( obj1 , old ) ;
0 commit comments