@@ -9,6 +9,8 @@ namespace Av1ador
99{
1010 public class Entry
1111 {
12+ private const string queue = "queue.xml" ;
13+ private const string backup = "queue.xml.bak" ;
1214 private static bool shouldsave ;
1315 private static int lastupdate ;
1416 private static int refresh ;
@@ -157,14 +159,29 @@ public static void Save(ListBox list, bool save = false)
157159
158160 public static void Load ( ListBox list )
159161 {
160- if ( System . IO . File . Exists ( " queue.xml" ) )
162+ if ( System . IO . File . Exists ( queue ) )
161163 {
162164 System . Xml . Serialization . XmlSerializer reader = new System . Xml . Serialization . XmlSerializer ( typeof ( Entry [ ] ) ) ;
163- StreamReader file = new StreamReader ( "queue.xml" ) ;
164- Entry [ ] entries = ( Entry [ ] ) reader . Deserialize ( file ) ;
165- file . Close ( ) ;
166- foreach ( Entry entry in entries )
167- list . Items . Add ( entry ) ;
165+ StreamReader file = new StreamReader ( queue ) ;
166+ Entry [ ] entries ;
167+ try
168+ {
169+ entries = ( Entry [ ] ) reader . Deserialize ( file ) ;
170+ file . Close ( ) ;
171+ foreach ( Entry entry in entries )
172+ list . Items . Add ( entry ) ;
173+ }
174+ catch
175+ {
176+ if ( System . IO . File . Exists ( backup ) )
177+ {
178+ file = new StreamReader ( backup ) ;
179+ entries = ( Entry [ ] ) reader . Deserialize ( file ) ;
180+ file . Close ( ) ;
181+ foreach ( Entry entry in entries )
182+ list . Items . Add ( entry ) ;
183+ }
184+ }
168185 }
169186 }
170187
@@ -264,8 +281,6 @@ public static void Update(int col, Video video, ListBox list, ListBox vf, ListBo
264281
265282 private static void Save_entries ( ListBox list )
266283 {
267- string queue = "queue.xml" ;
268- string backup = queue . Replace ( @"xml" , "xml.bak" ) ;
269284 if ( System . IO . File . Exists ( backup ) )
270285 System . IO . File . Delete ( backup ) ;
271286 System . IO . File . Move ( queue , backup ) ;
0 commit comments