Skip to content

Commit 5ddf920

Browse files
author
ohumeniuk
committed
added wait interval for previous installer completition
1 parent 8da7da7 commit 5ddf920

File tree

1 file changed

+28
-10
lines changed
  • eFormAPI/Installation/AllowMultipleVersionsBundle

1 file changed

+28
-10
lines changed

eFormAPI/Installation/AllowMultipleVersionsBundle/Program.cs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Security;
66
using Microsoft.Win32;
77
using System.Reflection;
8+
using System.Threading;
89

910
namespace AlowMultipleVersionsBundle
1011
{
@@ -14,6 +15,11 @@ static void Main(string[] args)
1415
{
1516
try
1617
{
18+
string path = Path.Combine(Path.GetTempPath(), "Eform Angular Frontend.exe");
19+
if (IsFileLocked(path))
20+
// wait for previous installer finish
21+
Thread.Sleep(2000);
22+
1723
var unistall =
1824
Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
1925
true);
@@ -27,17 +33,9 @@ static void Main(string[] args)
2733

2834
SetupIIS();
2935

30-
string path = Path.Combine(Path.GetTempPath(), "Eform Angular Frontend.exe");
31-
32-
try
33-
{
36+
if (!IsFileLocked(path))
3437
File.WriteAllBytes(path, Resources.Eform_Angular_Frontend);
35-
}
36-
catch
37-
{
38-
// in case if installer already running, there is no need to write its sources
39-
}
40-
38+
4139
var drive = DriveInfo.GetDrives().First(t => t.DriveType == DriveType.Fixed).Name;
4240
var tmpDir = Path.Combine(drive, "tmp");
4341
if (Directory.Exists(tmpDir))
@@ -56,6 +54,26 @@ static void Main(string[] args)
5654

5755
}
5856

57+
static bool IsFileLocked(string path)
58+
{
59+
FileStream stream = null;
60+
61+
try
62+
{
63+
stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None);
64+
}
65+
catch (IOException)
66+
{
67+
return true;
68+
}
69+
finally
70+
{
71+
if (stream != null)
72+
stream.Close();
73+
}
74+
return false;
75+
}
76+
5977
static void SetupIIS()
6078
{
6179
var featureNames = new[]

0 commit comments

Comments
 (0)