-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove clearPersistedFlag upon startup
The 'old' update mechanism edited the ini file *after* the upgrade and added the -clearPersistedState flag. The current mechanism does not need it, hence it must be removed if present
- Loading branch information
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
....abuchen.portfolio.bootstrap/src/name/abuchen/portfolio/bootstrap/IniFileManipulator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package name.abuchen.portfolio.bootstrap; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStreamWriter; | ||
import java.nio.charset.Charset; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
public class IniFileManipulator | ||
{ | ||
private static final String CLEAR_PERSISTED_STATE = "-clearPersistedState"; //$NON-NLS-1$ | ||
|
||
private List<String> lines = new ArrayList<String>(); | ||
private boolean isDirty = false; | ||
|
||
public void load() throws IOException | ||
{ | ||
lines = readAllLines(getIniFile()); | ||
} | ||
|
||
public void save() throws IOException | ||
{ | ||
write(getIniFile(), lines); | ||
isDirty = false; | ||
} | ||
|
||
public File getIniFile() | ||
{ | ||
String eclipseLauncher = System.getProperty("eclipse.launcher"); //$NON-NLS-1$ | ||
|
||
File path = new File(eclipseLauncher); | ||
|
||
String executable = path.getName().toString(); | ||
int p = executable.lastIndexOf('.'); | ||
String iniFileName = (p > 0 ? executable.substring(0, p) : executable) + ".ini"; //$NON-NLS-1$ | ||
|
||
return new File(path.getParentFile(), iniFileName); | ||
} | ||
|
||
public void unsetClearPersistedState() | ||
{ | ||
Iterator<String> iterator = lines.iterator(); | ||
while (iterator.hasNext()) | ||
{ | ||
String line = iterator.next(); | ||
if (line.trim().equals(CLEAR_PERSISTED_STATE)) | ||
{ | ||
iterator.remove(); | ||
isDirty = true; | ||
return; | ||
} | ||
} | ||
} | ||
|
||
public boolean isDirty() | ||
{ | ||
return isDirty; | ||
} | ||
|
||
private void write(File file, List<String> lines) throws IOException | ||
{ | ||
BufferedWriter out = new BufferedWriter( | ||
new OutputStreamWriter(new FileOutputStream(file), Charset.defaultCharset())); | ||
try | ||
{ | ||
for (String line : lines) | ||
{ | ||
out.write(line); | ||
out.write('\n'); | ||
} | ||
} | ||
finally | ||
{ | ||
out.close(); | ||
} | ||
} | ||
|
||
private List<String> readAllLines(File file) throws IOException | ||
{ | ||
List<String> answer = new ArrayList<String>(); | ||
|
||
FileInputStream in = new FileInputStream(file); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charset.defaultCharset())); | ||
|
||
try | ||
{ | ||
String line = null; | ||
while ((line = reader.readLine()) != null) | ||
answer.add(line); | ||
} | ||
finally | ||
{ | ||
reader.close(); | ||
} | ||
|
||
return answer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters