|
-
May 12th, 2011, 01:56 AM
#1
[RESOLVED] Retrieve both the source and destination when they are either side of an if statement
Hi,
How could I retrieve both the source and destination when they are either side of an if statement?
Here is my code:
vb Code:
Private Sub WinVersion()
Dim osinfo As OSVERSIONINFO
Dim retvalue As Integer
Dim sNextFile As String
osinfo.dwOSVersionInfoSize = 148
osinfo.szCSDVersion = Space$(128)
retvalue = GetVersionExA(osinfo)
If osinfo.dwMajorVersion = 7 Then 'Windows 7
If Not Dir$(App.path & "\xlive.dll") <> "" Then
path = "C:\Users\" & sUserName & "\AppData\Local\Rockstar Games\GTA IV\Settings\"
source = path
Else
path = "C:\Users\" & sUserName & "\Documents\Rockstar Games\GTA IV\savegames\"
destination = path
End If
ElseIf osinfo.dwMajorVersion = 6 Then 'Vista
If Not Dir$(App.path & "\xlive.dll") <> "" Then
path = "C:\Users\" & sUserName & "\AppData\Local\Rockstar Games\GTA IV\Settings\"
source = path
Else
path = "C:\Users\" & sUserName & "\Documents\Rockstar Games\GTA IV\savegames\"
destination = path
End If
ElseIf osinfo.dwMajorVersion = 5 Then 'XP
If Not Dir$(App.path & "\xlive.dll") <> "" Then
path = "C:\Documents and Settings\" & sUserName & "\Local Settings\Application Data\Rockstar Games\GTA IV\Settings\"
source = path
Else
path = "C:\Users\" & sUserName & "\Documents\Rockstar Games\GTA IV\savegames\"
destination = path
End If
'ElseIf osinfo.dwMajorVersion = 4 Then 'Win2k etc.
Else
End If
'copy
'Delete (path)
End Sub
I need to set the source and destination folders depending on whether or not the "xlive.dll" is location in the folder or not. If there is a better why to copy the files please show me.
Thanks,
Nightwalker
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 12th, 2011, 02:15 AM
#2
Re: Retrieve both the source and destination when they are either side of an if state
you should not be hardcoding the paths to folders that are not of fixed location (userdata), but returning them using specialfolders API or other method that will return the correct location, just because there is a default location, no guarantee they have not been moved
you could try Environ("appdata")
Last edited by westconn1; May 12th, 2011 at 02:20 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 12th, 2011, 02:59 AM
#3
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by westconn1
you could try Environ("appdata")
Ah ok, although, I tried that and it returned the "AppData\Roaming" instead of the "Local" folder when the files are actually located.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 12th, 2011, 01:55 PM
#4
Re: Retrieve both the source and destination when they are either side of an if state
path = "C:\Users\" .......
Don't have that folder. Your program wouldn't work on my machine.
How could I retrieve both the source and destination when they are either side of an if statement?
I see in your code you have all these If.....Else.....End If and the likes where two variables called destination and source, although I do not see them Dimentioned, are being initialized with values. Now you ask how to retrieve both of these values. What do you mean? You have both of them at the end of your last End If statement. Am I not reading your post correctly?
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 12th, 2011, 06:36 PM
#5
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by jmsrickland
path = "C:\Users\" .......
Don't have that folder. Your program wouldn't work on my machine.
What should I put instead? The hard-coded paths in the code above are in-fact those used by thew game on different operating system so how would I use those locations without hard coding the paths?
How could I retrieve both the source and destination when they are either side of an if statement?
I see in your code you have all these If.....Else.....End If and the likes where two variables called destination and source, although I do not see them Dimentioned, are being initialized with values. Now you ask how to retrieve both of these values. What do you mean? You have both of them at the end of your last End If statement. Am I not reading your post correctly?
I need to set both the source and destination regardless of what the path is. If the destination path is different from the default (source) path then the files would be copied to new location.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 12th, 2011, 06:44 PM
#6
Re: Retrieve both the source and destination when they are either side of an if state
at least from the roaming folder you know the correct path for the specific machine to appdata. so just change the last subfolder form roaming to local, then check it exists, different in XP of course
probably a select case would be better to all the iffs
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 12th, 2011, 06:53 PM
#7
Re: Retrieve both the source and destination when they are either side of an if state
I don't think you need to do all those If......End If when you can just use an API that gets you the correct path from the operating system.
Environ("appdata")
Now that one works for me but the other guy said it returned an incorrect path. Can't debug that one.
I think there is another API but I do not know it's name.
Why does your program have to use those paths anyway? Can you not just use App.Path? If the current App.Path does not have the inner folders you want or need to have then you can create them on the fly.
Do other applications (yours or someone elses) depend on those particular paths in relation to your programm?
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 12th, 2011, 07:42 PM
#8
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by jmsrickland
Why does your program have to use those paths anyway? Can you not just use App.Path? If the current App.Path does not have the inner folders you want or need to have then you can create them on the fly.
I need to check the location of the files for GTA IV under certain operating systems.
Do other applications (yours or someone elses) depend on those particular paths in relation to your program?
Those paths are the particular locations used to save data for GTA IV.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 12th, 2011, 09:23 PM
#9
Re: Retrieve both the source and destination when they are either side of an if state
Those paths are the particular locations used to save data for GTA IV.
OK. I don't know what GTA IV is
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 12th, 2011, 09:49 PM
#10
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by jmsrickland
Those paths are the particular locations used to save data for GTA IV.
OK. I don't know what GTA IV is
It's a game.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 12th, 2011, 10:03 PM
#11
Re: Retrieve both the source and destination when they are either side of an if state
app.path is not considered a good location for datafiles and need elevation under vista or w7, or some virtualised folder is substituted
afaik gta = grand theft auto
there maybe some registry key under gta that will give the correct path
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 12th, 2011, 10:10 PM
#12
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by westconn1
app.path is not considered a good location for datafiles and need elevation under vista or w7, or some virtualised folder is substituted
How would I change the above code, what should the above paths be?
Edit:
The variable sUserName holds the username of the currently logged in account which, is retrieved by another function, here it is.
Last edited by Nightwalker83; May 12th, 2011 at 10:15 PM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 12th, 2011, 10:16 PM
#13
Re: Retrieve both the source and destination when they are either side of an if state
It's a game.
I didn't know this. So, it's a game already made (commerical) and it uses those paths and you are making a VB program that needs to use those same paths for your program to either read or write files from those paths so that your program will function correctly. Is this correct? If not, then I don't understand why you need those exact paths.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 12th, 2011, 10:24 PM
#14
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by jmsrickland
It's a game.
I didn't know this. So, it's a game already made (commerical) and it uses those paths and you are making a VB program that needs to use those same paths for your program to either read or write files from those paths so that your program will function correctly. Is this correct? If not, then I don't understand why you need those exact paths.
That is correct! My program adjusts the game settings automatically so the player does not have to do it manually each time they play the game.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 12th, 2011, 10:36 PM
#15
Re: Retrieve both the source and destination when they are either side of an if state
OK, now that I understand that I still do not understand your question Retrieve both the source and destination when they are either side of an if statement
Do you need to know those paths before you enter into your If.....Else.....End If clauses? Because you will know them at the end.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 13th, 2011, 12:33 AM
#16
Re: Retrieve both the source and destination when they are either side of an if state
Yes, I need to set the source and destination paths regardless of the path in-case xlive.dll gets put in the folder. If xlive.dll is in the folder then the path would be different to the default path (the default path being the path used before xlive.dll was added), xlive modifies the games, one aspect of which, is that it changes the location of the save directory for the game.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 13th, 2011, 12:58 AM
#17
Re: Retrieve both the source and destination when they are either side of an if state
i assume, but have never tested that the "user" folder structure remains the same, regardless of where it is located
if that is true then
environ should return the correct value for xp, but with vista and w7 it will return the roaming folder below appdata, to replace that with the local, is just a matter of replacing "roaming" with "local"
some one may shoot me down here, but i do not know if the getspecialfolders API will find the local folder as different to the roaming one
i have not really studied the criteria as to what should go into each of those folders, but i am sure there will be a white paper or something with the details, available online
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 13th, 2011, 07:52 PM
#18
Re: Retrieve both the source and destination when they are either side of an if state
I found this on vbhelper:
vb Code:
Declare Function MakeTree Lib "imagehlp.dll" Alias _ "MakeSureDirectoryPathExists" (ByVal lpszPath As _ String) As Long ' Create the complete directory path. Private Sub MakePath(ByVal path As String) Dim directories As Variant Dim i As Integer Dim new_dir As String Dim dir_path As String ' Break the path into directories. directories = Split(path, "\") ' Build the subdirectories. For i = LBound(directories) To UBound(directories) ' Get the next directory in the path. new_dir = directories(i) ' Make sure the entry is non-empty. If Len(new_dir) > 0 Then ' Add the new directory to the path. dir_path = dir_path & new_dir & "\" ' Make sure we don't just have a drive ' specification. If Right$(new_dir, 1) <> ":" Then ' See if the directory already exists. If Dir$(dir_path, vbDirectory) = "" Then ' The directory doesn't exist. ' Make it. MkDir dir_path End If End If End If Next i End Sub
Although, I'm not sure if it does what you are talking about?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 13th, 2011, 08:08 PM
#19
Re: Retrieve both the source and destination when they are either side of an if state
as you are looking to locate an existing file, i do not see why that function would be useful to you at this time, that creates all sub folder required to create a specified path
search on specialfolders
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 13th, 2011, 09:16 PM
#20
Re: Retrieve both the source and destination when they are either side of an if state
I found this example which retrieves the path of the special folders. The only thing is that uses "shfolder.dll" instead of just the code. I would rather compile my program into a stand-alone exe rather than having to rely on external dlls, ocx, etc doing the work.
Edit:
This code by VBForums own Dave Sell does the same thing except it is in a module.
Dave Sells code still returns the "Roaming" folder whereas I need to retrieve the "Local" folder.
I replied to the above thread hopefully someone can point me in the right direction.
Last edited by Nightwalker83; May 13th, 2011 at 09:49 PM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 14th, 2011, 08:14 PM
#21
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by Nightwalker83
I replied to the above thread hopefully someone can point me in the right direction.
Here is the solution:
 Originally Posted by jpbro
Because there's a mistake in the SpecialFolders Enum:
Local_AppData = CSIDL_APPDATA
Should be:
Local_AppData = CSIDL_LOCAL_APPDATA
Last edited by Nightwalker83; May 14th, 2011 at 09:00 PM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 14th, 2011, 09:00 PM
#22
Re: Retrieve both the source and destination when they are either side of an if state
How do you declare OSVERSIONINFO
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 14th, 2011, 09:03 PM
#23
Re: Retrieve both the source and destination when they are either side of an if state
Like so:
vb Code:
'Source: http://social.msdn.microsoft.com/Forums/en/vbide/thread/395b12fd-ccfc-4281-b1b3-4c69b56f8b85
Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
Public Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Procedure :-
Private Sub WinVersion()
Dim osinfo As OSVERSIONINFO
Dim retvalue As Integer
osinfo.dwOSVersionInfoSize = 148
osinfo.szCSDVersion = Space$(128)
retvalue = GetVersionExA(osinfo)
If osinfo.dwMajorVersion = 6 Then 'Vista
ElseIf osinfo.dwMajorVersion = 5 Then 'XP
ElseIf osinfo.dwMajorVersion = 4 Then 'Win2k etc.
Else
End If
End Sub
See line two.
Edit:
I removed the previous code I had posted because after testing I found it was not working.
Last edited by Nightwalker83; May 14th, 2011 at 09:06 PM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 14th, 2011, 09:27 PM
#24
Re: Retrieve both the source and destination when they are either side of an if state
Yeah but now you're not showing how to get the correct paths and that's what I needed to know.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 14th, 2011, 11:02 PM
#25
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by jmsrickland
Yeah but now you're not showing how to get the correct paths and that's what I needed to know.
I'm not sure I follow! The paths I originally used were hard coded. Although, I have written this which works:
vb Code:
Private Sub WinVersion() 'Retrieve the current operating system and set the settings path accordingly 'http://social.msdn.microsoft.com/Forums/en/vbide/thread/395b12fd-ccfc-4281-b1b3-4c69b56f8b85 Dim osinfo As OSVERSIONINFO Dim retvalue As Integer Dim sNextFile As String osinfo.dwOSVersionInfoSize = 148 osinfo.szCSDVersion = Space$(128) retvalue = GetVersionExA(osinfo) If osinfo.dwMajorVersion = 7 Then 'Windows 7 If Not Dir$(App.Path & "\xlive.dll") <> "" Then Path = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\" 'source = path Else Path = GetSpecialfolder(SpecialFolders.MyDocuments) & "\Rockstar Games\GTA IV\savegames\" 'destination = path End If ElseIf osinfo.dwMajorVersion = 6 Then 'Vista If Not Dir$(App.Path & "\xlive.dll") <> "" Then Path = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\" 'source = path Else Path = GetSpecialfolder(SpecialFolders.MyDocuments) & "\Rockstar Games\GTA IV\savegames\" 'destination = path End If ElseIf osinfo.dwMajorVersion = 5 Then 'XP If Not Dir$(App.Path & "\xlive.dll") <> "" Then Path = GetSpecialfolder(SpecialFolders.Drives) & sUserName & "\" & GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\" 'source = path Else Path = "C:\Users\" & sUserName & "\" & GetSpecialfolder(SpecialFolders.MyDocuments) & "Rockstar Games\GTA IV\savegames\" 'destination = path End If 'ElseIf osinfo.dwMajorVersion = 4 Then 'Win2k etc. Else End If 'copy 'Delete (Path) End Sub
I haven't configured the XP option yet but the Vista and the Windows 7 options work as expected.
Edit:
I guess to solve the source and destination problem I could place both source and destination on either side of the "else".
Last edited by Nightwalker83; May 14th, 2011 at 11:06 PM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 15th, 2011, 12:50 AM
#26
Re: Retrieve both the source and destination when they are either side of an if state
Are you testing this on all these various versions of Windows? If not, then how do you know they are correct and they work?
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 15th, 2011, 01:05 AM
#27
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by jmsrickland
Are you testing this on all these various versions of Windows? If not, then how do you know they are correct and they work?
Of course I have tested on those versions of Windows. I have Windows 7 on my laptop and Vista on my PC. I could probably install XP on my PC if I wanted to.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 15th, 2011, 02:48 AM
#28
Re: Retrieve both the source and destination when they are either side of an if state
@Night: Can you please tell me what exactly are you doing ? I mean, what you want to do. 
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
May 15th, 2011, 03:28 AM
#29
Re: Retrieve both the source and destination when they are either side of an if state
What the above code was originally designed to do was to delete the default control settings for Grand Theft Auto IV. Now, I am trying to make the program detect where the GTA IV saves are and if an additional file "xlive.dll" is in the games directory move the saves to a different location on the hard drive.
Last edited by Nightwalker83; May 15th, 2011 at 09:20 PM.
Reason: Fixed spelling!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 15th, 2011, 09:38 AM
#30
Re: Retrieve both the source and destination when they are either side of an if state
I may be wrong but doesn't the SHGetSpecialFolderLocation API return the proper path regardless of the OS?
Code:
Option Explicit
Private Declare Function SHGetSpecialFolderLocation Lib "Shell32.dll" (ByVal hwndOwner As Long, _
ByVal nFolder As Long, ByRef ppidl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Declare Sub CoTaskMemFree Lib "ole32" (ByVal hMem As Long)
Const CSIDL_PERSONAL = &H5 '(user)\My Documents
Const CSIDL_LOCAL_APPDATA = &H1C '(user)\Local Settings\Application Data
Private Sub Form_Load()
MsgBox GetPath
End Sub
Private Function GetSpecialFolder(ByVal lCSIDL As Long) As String
Const S_OK As Long = 0
Const MAX_PATH As Long = 260
Dim sPath As String
Dim lIdl As Long
If SHGetSpecialFolderLocation(0, lCSIDL, lIdl) = S_OK Then
sPath = Space$(MAX_PATH)
If SHGetPathFromIDList(lIdl, sPath) Then
CoTaskMemFree lIdl
GetSpecialFolder = Left$(sPath, InStr(sPath, vbNullChar) - 1)
End If
End If
End Function
Private Function GetPath()
If Not Dir$(App.Path & "\xlive.dll") <> "" Then
GetPath = GetSpecialFolder(CSIDL_LOCAL_APPDATA) & "\Rockstar Games\GTA IV\Settings\"
Else
GetPath = GetSpecialFolder(CSIDL_PERSONAL) & "\Rockstar Games\GTA IV\savegames\"
End If
End Function
-
May 16th, 2011, 07:10 AM
#31
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by MarkT
I may be wrong but doesn't the SHGetSpecialFolderLocation API return the proper path regardless of the OS?
I think there is a different method for Windows XP and before, I thought I saw a thread regarding it on the forums.
Edit:
Damn, I can't get the files to copy from one location to another. Below is the code I am using.
vb Code:
Private Sub WinVersion() 'Retrieve the current operating system and set the settings path accordingly 'http://social.msdn.microsoft.com/Forums/en/vbide/thread/395b12fd-ccfc-4281-b1b3-4c69b56f8b85 Dim osinfo As OSVERSIONINFO Dim retvalue As Integer Dim sNextFile As String osinfo.dwOSVersionInfoSize = 148 osinfo.szCSDVersion = Space$(128) retvalue = GetVersionExA(osinfo) If osinfo.dwMajorVersion = 7 Then 'Windows 7 If Not FileExists(App.Path & "\xlive.dll") Then source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\" destination = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\" Else source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\" destination = GetSpecialfolder(SpecialFolders.MyDocuments) & "\Rockstar Games\GTA IV\savegames\" End If ElseIf osinfo.dwMajorVersion = 6 Then 'Vista If Not FileExists(App.Path & "\xlive.dll") Then source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\" destination = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\" Else source = "\Rockstar Games\GTA IV\Settings\" destination = "c:\Rockstar Games\GTA IV\savegames\" 'GetSpecialfolder(SpecialFolders.Local_AppData) & 'GetSpecialfolder(SpecialFolders.MyDocuments) & End If ElseIf osinfo.dwMajorVersion = 5 Then 'XP If Not FileExists(App.Path & "\xlive.dll") Then source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\" destination = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\" Else source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\" destination = GetSpecialfolder(SpecialFolders.MyDocuments) & "Rockstar Games\GTA IV\savegames\" End If 'ElseIf osinfo.dwMajorVersion = 4 Then 'Win2k etc. Else End If 'Call Delete(source) 'http://www.vbforums.com/showthread.php?t=641462&highlight=copy+folder Call VBCopyFolder(source, destination) Call Copy(source) End Sub Private Sub Copy(source) Dim c As String c = source + "\savegames\user_e00006645743f1a9\" sNextFile = Dir$(c + "*.*", vbNormal + vbHidden + vbReadOnly) Do While sNextFile <> "" SetAttr c & sNextFile, vbNormal FileCopy c, destination sNextFile = Dir$ Loop End Sub
I am also using the code here.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 16th, 2011, 07:40 AM
#32
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by Nightwalker83
I think there is a different method for Windows XP and before, I thought I saw a thread regarding it on the forums.
The only 2 OSs I have to test against are WinXP and Win7 64bit and the SHGetSpecialFolderLocation API returns the correct path for both My Documents and the Users App Data folder.
I just don't see a need for any if statements. Just test it to see if it works.
-
May 16th, 2011, 06:37 PM
#33
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by MarkT
The only 2 OSs I have to test against are WinXP and Win7 64bit and the SHGetSpecialFolderLocation API returns the correct path for both My Documents and the Users App Data folder.
I just don't see a need for any if statements. Just test it to see if it works.
Yes, thank you it worked. Now I need to test the copy method posted above and see if I can get that to work without having to hard code the paths.
Edit:
I just tested the copy method (above) using your code and for some reason it still doesn't recognize the path as being valid, although, if I hard-code the path it creates the destination folder as excepted but still does not move the files to the destination directory.
Last edited by Nightwalker83; May 16th, 2011 at 08:28 PM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 17th, 2011, 07:19 PM
#34
Re: Retrieve both the source and destination when they are either side of an if state
Any ideas on why the file copy method is not working using the code in post #31?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 17th, 2011, 07:35 PM
#35
Re: Retrieve both the source and destination when they are either side of an if state
Place a breakpoint on line 48. When you reach the breakpoint check the value of c. I bet you will find a double backslash in the path.
-
May 17th, 2011, 08:11 PM
#36
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by MarkT
Place a breakpoint on line 48. When you reach the breakpoint check the value of c. I bet you will find a double backslash in the path.
That doesn't appear to be the case I put a debug.print after line 48 and this was the result:
C:\Users\User\AppData\Local\Rockstar Games\GTA IV\savegames\user_e00006645743f1a9\
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 17th, 2011, 08:26 PM
#37
Re: Retrieve both the source and destination when they are either side of an if state
There is no file name in the path unless it's user_e00006645743f1a9 and if it is then remove the last \
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 17th, 2011, 08:55 PM
#38
Re: Retrieve both the source and destination when they are either side of an if state
 Originally Posted by Nightwalker83
I think there is a different method for Windows XP and before, I thought I saw a thread regarding it on the forums.
Edit:
Damn, I can't get the files to copy from one location to another. Below is the code I am using.
vb Code:
Private Sub WinVersion()
'Retrieve the current operating system and set the settings path accordingly
'http://social.msdn.microsoft.com/Forums/en/vbide/thread/395b12fd-ccfc-4281-b1b3-4c69b56f8b85
Dim osinfo As OSVERSIONINFO
Dim retvalue As Integer
Dim sNextFile As String
osinfo.dwOSVersionInfoSize = 148
osinfo.szCSDVersion = Space$(128)
retvalue = GetVersionExA(osinfo)
If osinfo.dwMajorVersion = 7 Then 'Windows 7
If Not FileExists(App.Path & "\xlive.dll") Then
source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\"
destination = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
Else
source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
destination = GetSpecialfolder(SpecialFolders.MyDocuments) & "\Rockstar Games\GTA IV\savegames\"
End If
ElseIf osinfo.dwMajorVersion = 6 Then 'Vista
If Not FileExists(App.Path & "\xlive.dll") Then
source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\"
destination = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
Else
source = "\Rockstar Games\GTA IV\Settings\"
destination = "c:\Rockstar Games\GTA IV\savegames\"
'GetSpecialfolder(SpecialFolders.Local_AppData) &
'GetSpecialfolder(SpecialFolders.MyDocuments) &
End If
ElseIf osinfo.dwMajorVersion = 5 Then 'XP
If Not FileExists(App.Path & "\xlive.dll") Then
source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\"
destination = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
Else
source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\"
destination = GetSpecialfolder(SpecialFolders.MyDocuments) & "Rockstar Games\GTA IV\savegames\"
End If
'ElseIf osinfo.dwMajorVersion = 4 Then 'Win2k etc.
Else
End If
'Call Delete(source)
'http://www.vbforums.com/showthread.php?t=641462&highlight=copy+folder
Call VBCopyFolder(source, destination)
Call Copy(source)
End Sub
Private Sub Copy(source)
Dim c As String
c = source + "\savegames\user_e00006645743f1a9\"
sNextFile = Dir$(c + "*.*", vbNormal + vbHidden + vbReadOnly)
Do While sNextFile <> ""
SetAttr c & sNextFile, vbNormal
FileCopy c, destination
sNextFile = Dir$
Loop
End Sub
I am also using the code here.
Night
I did some indenting to help me follow.
Sorry if this is too obvious, but did you check to see
if source and destination have the expected
values from each of your branches?
Spoo
-
May 17th, 2011, 09:50 PM
#39
Re: Retrieve both the source and destination when they are either side of an if state
I finally managed to get the code working it moves both the folder and files as excepted.
vb Code:
Private Function GetPath() If Not Dir$(App.Path & "\xlive.dll") <> "" Then source = GetSpecialFolder(CSIDL_LOCAL_APPDATA) & "\Rockstar Games\GTA IV\" destination = GetSpecialFolder(CSIDL_LOCAL_APPDATA) & "\Rockstar Games\GTA IV\" Else source = GetSpecialFolder(CSIDL_LOCAL_APPDATA) & "\Rockstar Games\GTA IV\" destination = GetSpecialFolder(CSIDL_PERSONAL) & "\Rockstar Games\GTA IV\" End If Call Copy(source) End Function Private Sub Copy(source) Dim c As String c = source & "savegames\user_e00006645743f1a9" destination = destination & "savegames\user_e00006645743f1a9" Call VBCopyFolder(c, destination) End Sub
I am using the above code in conjunction with the code I linked to in post #31.
Edit:
 Originally Posted by Spoo
Night
I did some indenting to help me follow.
Sorry if this is too obvious, but did you check to see
if source and destination have the expected
values from each of your branches?
Spoo
Yeah, I encountered that problem and found the solution see the above code.
Last edited by Nightwalker83; May 17th, 2011 at 09:54 PM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|