@@ -66,66 +66,53 @@ static void Main(string[] args)
66
66
}
67
67
}
68
68
69
- // Download and parse component list
70
- while ( true )
69
+ Stream listStream = null ;
70
+
71
+ // Attempt to download and parse component list
72
+ try
73
+ {
74
+ listStream = new MemoryStream ( new WebClient ( ) . DownloadData ( FPM . RepoXml ) ) ;
75
+ FPM . XmlTree . Load ( listStream ) ;
76
+ }
77
+ catch ( Exception e )
71
78
{
72
- byte [ ] listData = new byte [ ] { } ;
79
+ string failedAction = e is XmlException ? "parsed" : "downloaded" ;
73
80
74
- try
75
- {
76
- listData = new WebClient ( ) . DownloadData ( FPM . RepoXml ) ;
77
- }
78
- catch
79
- {
80
- FPM . GenericError (
81
- "The component list could not be downloaded! An offline backup will be used instead.\n \n " +
82
- "Verify that your internet connection is working and that your component source is not misconfigured."
83
- ) ;
81
+ FPM . GenericError (
82
+ $ "The component list could not be { failedAction } ! An offline backup will be used instead.\n \n " +
83
+ "Verify that your internet connection is working and that your component source is not misconfigured."
84
+ ) ;
84
85
85
- FPM . OfflineMode = true ;
86
- }
86
+ FPM . OfflineMode = true ;
87
+ }
87
88
88
- Stream listStream = null ;
89
- string backupPath = Path . Combine ( FPM . SourcePath , "Components" , "components.bak" ) ;
89
+ string backupPath = Path . Combine ( FPM . SourcePath , "Components" , "components.bak" ) ;
90
90
91
- if ( ! FPM . OfflineMode )
92
- {
93
- try
94
- {
95
- listStream = File . Create ( backupPath ) ;
96
- listStream . Write ( listData , 0 , listData . Length ) ;
97
- }
98
- catch
99
- {
100
- listStream = new MemoryStream ( listData ) ;
101
- }
102
- }
103
- else
91
+ // Create backup if component list was successfully downloaded and parsed; otherwise, load from backup
92
+ if ( ! FPM . OfflineMode )
93
+ {
94
+ try
104
95
{
105
- try
106
- {
107
- listStream = new FileStream ( backupPath , FileMode . Open , FileAccess . Read ) ;
108
- }
109
- catch
96
+ using ( var fileStream = new FileStream ( backupPath , FileMode . OpenOrCreate , FileAccess . Write ) )
110
97
{
111
- FPM . GenericError ( "Failed to load component list from offline backup!" ) ;
112
- Environment . Exit ( 1 ) ;
98
+ listStream . Position = 0 ;
99
+ listStream . CopyTo ( fileStream ) ;
113
100
}
114
101
}
115
-
116
- listStream . Position = 0 ;
117
-
102
+ catch { }
103
+ }
104
+ else
105
+ {
118
106
try
119
107
{
120
- FPM . XmlTree = new XmlDocument ( ) ;
108
+ listStream = new FileStream ( backupPath , FileMode . Open , FileAccess . Read ) ;
121
109
FPM . XmlTree . Load ( listStream ) ;
122
110
}
123
111
catch
124
112
{
125
- FPM . ParseError ( "The XML markup is malformed." ) ;
113
+ FPM . GenericError ( "Failed to load component list from offline backup!" ) ;
114
+ Environment . Exit ( 1 ) ;
126
115
}
127
-
128
- break ;
129
116
}
130
117
131
118
// Verify that the configured Flashpoint path is valid
0 commit comments