Instantly share code, notes, and snippets.

Embed
What would you like to do?
private Array getProjectList()
{
// get the project list from a file.
str startProjFileName;
TextBuffer tbProjList;
Array projects = new Array(Types::String);
int nProjects;
startProjFileName = this.getStartProjFileName();
tbProjList = new TextBuffer();
// if it doesn't exist, create an empty file & return.
if (!WinAPI::fileExists(startProjFileName))
{
WinAPI::createFile(startProjFileName);
return projects;
}
// should probably assert permission...
tbProjList.fromFile(startProjFileName);
nProjects = 0;
while (tbProjList.nextToken(true))
{
nProjects++;
projects.value(nProjects, tbProjList.token());
}
return projects;
}
private boolean writeProjectList(Array projects)
{
// write out a project list to file, overwriting existing list.
str startProjFileName;
TextBuffer tbProjList;
int i;
startProjFileName = this.getStartProjFileName();
tbProjList = new TextBuffer();
for (i=1; i <= projects.lastIndex(); i++)
{
tbProjList.appendText(projects.value(i));
tbProjList.appendText("\n");
}
return tbProjList.toFile(startProjFileName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment