The Ro Editor uses a semaphore File (ROEditor.OWN) to control or limit the number of people that can edit the RO database. Only one person can edit at a time. When the editor is opened, the code checks to see if the Semaphore flag exists. If it does, the code exits immediately. If it didn't exist, it was created. When the editor was exited properly, the file was closed and deleted.

Unfortunately, if the editor crashed, the file would be left and nobody could open the RO Editor.  To this point, this would have to be fixedd manually.  With this change, the code deletes the file rather than checking for its existance.  If the deletion fails (which indicates that the editor is in use) a MessageBox will be displayed and identify who has the RO Editor.
This commit is contained in:
Rich 2015-09-15 21:40:15 +00:00
parent 2bd80c5469
commit 1d360b719e

View File

@ -1556,10 +1556,25 @@ namespace ROEditor
if (StartupROEditor)
{
// open an existing file, or create a new one
// The ROEditor.OWN file assures that only one individual at a time can edit the RO database.
// The file is opened and kept open while the user is editing the database. The contents of the
// file will identify the current user and state when the edit session began.
try
{
fiown = new FileInfo("RoEditor.own");
try {
// Try to delete the owner file. If another process has the file open, this delete will fail.
// If the file is closed, it will be deleted, and the user will be placed in the editor. The users
// name and the time when this session began will be placed in the owner file.
fiown.Delete();
}
catch(Exception ex)
{
fsown = fiown.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
TextReader tr1 = new StreamReader(fsown);
string who1 = tr1.ReadToEnd();
MessageBox.Show(ex.Message + "\r\n\r\n" + who1, "RO Editor In Use", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
fsown = fiown.Open(FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);
TextReader tr = new StreamReader(fsown);
string who = tr.ReadToEnd();