Skip to content

Commit 722f977

Browse files
author
Peter Palotas
committed
Changed the extension of the external file to .projectSets.json to not break backwards compatibility (i.e. not changing the format of the vspsm file).
1 parent 9e29a95 commit 722f977

2 files changed

Lines changed: 22 additions & 29 deletions

File tree

Source/LoadedProjectsProfileManagerPackage.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ private void SaveOptionsExternal()
338338
m_repository.SaveJson(fs);
339339
}
340340

341-
string targetPath = Path.ChangeExtension(info.SolutionFile, ".vspsm");
341+
string targetPath = Path.ChangeExtension(info.SolutionFile, ".projectSets.json");
342342

343343
if (!AreFilesIdentical(tempPath, targetPath))
344344
{
@@ -405,25 +405,26 @@ private static bool AreFilesIdentical(string file1, string file2, int bufferSize
405405
}
406406
}
407407

408-
409408
private void LoadOptionsExternal()
410409
{
411410
SolutionManager solMgr = GetSolutionManager();
412411
if (solMgr != null)
413412
{
414413
SolutionInfo info = solMgr.GetSolutionInfo();
415414

416-
string targetPath = Path.ChangeExtension(info.SolutionFile, ".vspsm");
417415

418-
if (File.Exists(targetPath))
416+
string targetBinaryPath = Path.ChangeExtension(info.SolutionFile, ".vspsm");
417+
string targetJsonPath = Path.ChangeExtension(info.SolutionFile, ".projectSets.json");
418+
419+
if (File.Exists(targetJsonPath))
420+
{
421+
m_repository.LoadJson(targetJsonPath, solMgr);
422+
}
423+
else if (File.Exists(targetBinaryPath))
419424
{
420-
using (FileStream fs = new FileStream(targetPath, FileMode.Open, FileAccess.Read, FileShare.Read))
425+
using (FileStream fs = new FileStream(targetBinaryPath, FileMode.Open, FileAccess.Read, FileShare.Read))
421426
{
422-
if (!m_repository.TryLoadJson(fs, solMgr))
423-
{
424-
fs.Position = 0;
425-
m_repository.LoadBinary(fs, solMgr);
426-
}
427+
m_repository.LoadBinary(fs, solMgr);
427428
}
428429
}
429430
}

Source/Model/IProjectSetRepository.cs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,22 @@ public void SaveJson(JsonWriter writer)
116116
serializer.Serialize(writer, m_projectSets);
117117
}
118118

119-
public bool TryLoadJson(Stream stream, SolutionManager solMgr)
119+
public void LoadJson(string fileName, SolutionManager solMgr)
120120
{
121-
try
121+
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
122+
using (StreamReader streamReader = new StreamReader(fs, Encoding.UTF8, true, 4096, true))
123+
using (JsonReader reader = new JsonTextReader(streamReader))
122124
{
123-
using (StreamReader streamReader = new StreamReader(stream, Encoding.UTF8, true, 4096, true))
124-
using (JsonReader reader = new JsonTextReader(streamReader))
125+
JsonSerializer serializer = JsonSerializer.Create();
126+
var projectSets = serializer.Deserialize<ObservableCollection<ProjectSet>>(reader);
127+
if (projectSets == null)
125128
{
126-
JsonSerializer serializer = JsonSerializer.Create();
127-
var projectSets = serializer.Deserialize<ObservableCollection<ProjectSet>>(reader);
128-
if (projectSets == null)
129-
{
130-
return false;
131-
}
132-
133-
m_projectSets.Clear();
134-
foreach (var projectSet in projectSets)
135-
m_projectSets.Add(projectSet);
129+
projectSets = new ObservableCollection<ProjectSet>();
136130
}
137131

138-
return true;
139-
}
140-
catch (JsonReaderException)
141-
{
142-
return false;
132+
m_projectSets.Clear();
133+
foreach (var projectSet in projectSets)
134+
m_projectSets.Add(projectSet);
143135
}
144136
}
145137

0 commit comments

Comments
 (0)