Go Back   FileForums > Game Backup > PC Games > PC Games - CD/DVD Conversions > Conversion Tutorials

Reply
 
Thread Tools Display Modes
  #1  
Old 19-12-2021, 03:57
Cuttlas's Avatar
Cuttlas Cuttlas is offline
Registered User
 
Join Date: Aug 2020
Location: Near You :)
Posts: 56
Thanks: 19
Thanked 8 Times in 4 Posts
Cuttlas is on a distinguished road
Lightbulb Check whether file is in use

is there any way to check if a file is in use via inno setup?
Reply With Quote
Sponsored Links
  #2  
Old 19-12-2021, 20:42
Razor12911's Avatar
Razor12911 Razor12911 is offline
Programmer
 
Join Date: Jul 2012
Location: South Africa
Posts: 3,630
Thanks: 2,003
Thanked 10,317 Times in 2,198 Posts
Razor12911 is on a distinguished road
You need to open the file with the intent to both read and writing to it, if this operation fails then it means the file is in use.

Code:
function IsFileInUse(Filename: String): Boolean;
begin
  Result := False;  
  try
    with TFileStream.Create(Filename,fmOpenReadWrite) do // this should fail
    try
    finally
      Free;
    end;
  except
    Result := True; // this handles the exception and tells you the file is in use
  end;
end;

Last edited by Razor12911; 19-12-2021 at 20:47.
Reply With Quote
The Following User Says Thank You to Razor12911 For This Useful Post:
Cuttlas (21-12-2021)
  #3  
Old 20-12-2021, 21:26
Cuttlas's Avatar
Cuttlas Cuttlas is offline
Registered User
 
Join Date: Aug 2020
Location: Near You :)
Posts: 56
Thanks: 19
Thanked 8 Times in 4 Posts
Cuttlas is on a distinguished road
Lightbulb

what happens if the file is so big? does it take too long?
Reply With Quote
  #4  
Old 21-12-2021, 01:57
Razor12911's Avatar
Razor12911 Razor12911 is offline
Programmer
 
Join Date: Jul 2012
Location: South Africa
Posts: 3,630
Thanks: 2,003
Thanked 10,317 Times in 2,198 Posts
Razor12911 is on a distinguished road
Size is irrelevant
Reply With Quote
  #5  
Old 21-12-2021, 08:17
Cesar82's Avatar
Cesar82 Cesar82 is offline
Registered User
 
Join Date: May 2011
Location: Brazil
Posts: 775
Thanks: 1,289
Thanked 1,641 Times in 559 Posts
Cesar82 is on a distinguished road
@Razor12911, Just curiosity...
Is it necessary to use "try" "finally"?
It could not be used simply "do Free;"
Reply With Quote
  #6  
Old 21-12-2021, 23:50
Razor12911's Avatar
Razor12911 Razor12911 is offline
Programmer
 
Join Date: Jul 2012
Location: South Africa
Posts: 3,630
Thanks: 2,003
Thanked 10,317 Times in 2,198 Posts
Razor12911 is on a distinguished road
You can write "do Free", it's the same thing only for this case as there is no code within the try..finally statement that would cause an exception.
Reply With Quote
The Following 2 Users Say Thank You to Razor12911 For This Useful Post:
Cesar82 (22-12-2021), L33THAK0R (28-12-2021)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Borderlands 2 GOTY omdj PC Games - CD/DVD Conversions 11 22-01-2021 08:22
Useful Dll for Inno Setup users peterf1999 Conversion Tutorials 88 01-12-2017 16:00
Midway Arcade Treasures 2 kartking CD/DVD Copy Protections & Utilities 5 19-11-2007 08:19
HELP ME PLZ!!!! Dalvin DC Games 0 02-01-2001 22:14



All times are GMT -7. The time now is 17:43.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.
Copyright 2000-2020, FileForums @ https://fileforums.com