Skip to content

Commit 61d1cd9

Browse files
authored
Crash Fix
-Fixed a crash when the Installation path didn't had the enough permissions to save the mapped databases
1 parent 34d684c commit 61d1cd9

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

AiPostgreWinForms/FrmAiPostgre.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -814,19 +814,25 @@ private void btn_map_Click(object sender, EventArgs e)
814814
WriteIndented = true // JSON format
815815
};
816816

817-
if (!Directory.Exists("MappedDB"))
818-
Directory.CreateDirectory("MappedDB");
819-
File.WriteAllText("MappedDB\\" + txt_db.Text + ".json", System.Text.Json.JsonSerializer.Serialize(tables, opcions));
817+
try
818+
{
819+
if (!Directory.Exists("MappedDB"))
820+
Directory.CreateDirectory("MappedDB");
821+
File.WriteAllText("MappedDB\\" + txt_db.Text + ".json", System.Text.Json.JsonSerializer.Serialize(tables, opcions));
820822

823+
lv_maps.Invoke((MethodInvoker)(() =>
824+
{
825+
lv_maps.Items.Add(txt_db.Text);
826+
}));
827+
}
828+
catch (Exception ex)
829+
{
830+
MessageBox.Show("The Mapped Database couldn't be saved in your drive, make sure the installation path have the necessary permissions or start the program as Administrator.","Permissions Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
831+
}
821832
gb_map.Invoke((MethodInvoker)(() =>
822833
{
823834
gb_map.Enabled = true;
824835
}));
825-
826-
lv_maps.Invoke((MethodInvoker)(() =>
827-
{
828-
lv_maps.Items.Add(txt_db.Text);
829-
}));
830836
}
831837
});
832838
thread.Start();
@@ -862,9 +868,16 @@ private void btn_deletemap_Click(object sender, EventArgs e)
862868
var result = MessageBox.Show("Are you sure you want to delete this Mapped Database?", "Delete Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
863869
if (result == DialogResult.Yes)
864870
{
865-
File.Delete("MappedDB\\" + lv_maps.FocusedItem.Text + ".json");
866-
json = "";
867-
lv_maps.FocusedItem.Remove();
871+
try
872+
{
873+
File.Delete("MappedDB\\" + lv_maps.FocusedItem.Text + ".json");
874+
json = "";
875+
lv_maps.FocusedItem.Remove();
876+
}
877+
catch (Exception ex)
878+
{
879+
MessageBox.Show("The Mapped Database couldn't be deleted from your drive, make sure the installation path have the necessary permissions or start the program as Administrator.", "Permissions Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
880+
}
868881
}
869882
}
870883
}

0 commit comments

Comments
 (0)