Results 1 to 39 of 39

Thread: [RESOLVED] Retrieve both the source and destination when they are either side of an if statement

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Resolved [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:
    1. Private Sub WinVersion()
    2.     Dim osinfo As OSVERSIONINFO
    3.     Dim retvalue As Integer
    4.     Dim sNextFile As String
    5.     osinfo.dwOSVersionInfoSize = 148
    6.     osinfo.szCSDVersion = Space$(128)
    7.     retvalue = GetVersionExA(osinfo)
    8.     If osinfo.dwMajorVersion = 7 Then 'Windows 7
    9.    If Not Dir$(App.path & "\xlive.dll") <> "" Then
    10.     path = "C:\Users\" & sUserName & "\AppData\Local\Rockstar Games\GTA IV\Settings\"
    11.     source = path
    12.     Else
    13.     path = "C:\Users\" & sUserName & "\Documents\Rockstar Games\GTA IV\savegames\"
    14.     destination = path
    15.     End If
    16.     ElseIf osinfo.dwMajorVersion = 6 Then 'Vista
    17.     If Not Dir$(App.path & "\xlive.dll") <> "" Then
    18.     path = "C:\Users\" & sUserName & "\AppData\Local\Rockstar Games\GTA IV\Settings\"
    19.      source = path
    20.       Else
    21.     path = "C:\Users\" & sUserName & "\Documents\Rockstar Games\GTA IV\savegames\"
    22.      destination = path
    23.     End If
    24.     ElseIf osinfo.dwMajorVersion = 5 Then 'XP
    25.     If Not Dir$(App.path & "\xlive.dll") <> "" Then
    26.     path = "C:\Documents and Settings\" & sUserName & "\Local Settings\Application Data\Rockstar Games\GTA IV\Settings\"
    27.      source = path
    28.     Else
    29.     path = "C:\Users\" & sUserName & "\Documents\Rockstar Games\GTA IV\savegames\"
    30.      destination = path
    31.     End If
    32.     'ElseIf osinfo.dwMajorVersion = 4 Then 'Win2k etc.
    33.     Else
    34.     End If
    35.     'copy
    36.     'Delete (path)
    37. 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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  3. #3

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by westconn1 View Post
    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

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  5. #5

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by jmsrickland View Post
    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

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  8. #8

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by jmsrickland View Post
    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

  9. #9
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  10. #10

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by jmsrickland View Post
    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

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Retrieve both the source and destination when they are either side of an if state

    If the current App.Path
    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

  12. #12

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by westconn1 View Post
    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

  13. #13
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  14. #14

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by jmsrickland View Post
    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

  15. #15
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  16. #16

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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

  17. #17
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  18. #18

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    I found this on vbhelper:

    vb Code:
    1. Declare Function MakeTree Lib "imagehlp.dll" Alias _
    2.     "MakeSureDirectoryPathExists" (ByVal lpszPath As _
    3.     String) As Long
    4.  
    5. ' Create the complete directory path.
    6. Private Sub MakePath(ByVal path As String)
    7. Dim directories As Variant
    8. Dim i As Integer
    9. Dim new_dir As String
    10. Dim dir_path As String
    11.  
    12.     ' Break the path into directories.
    13.     directories = Split(path, "\")
    14.  
    15.     ' Build the subdirectories.
    16.     For i = LBound(directories) To UBound(directories)
    17.         ' Get the next directory in the path.
    18.         new_dir = directories(i)
    19.  
    20.         ' Make sure the entry is non-empty.
    21.         If Len(new_dir) > 0 Then
    22.             ' Add the new directory to the path.
    23.             dir_path = dir_path & new_dir & "\"
    24.  
    25.             ' Make sure we don't just have a drive
    26.             ' specification.
    27.             If Right$(new_dir, 1) <> ":" Then
    28.                 ' See if the directory already exists.
    29.                 If Dir$(dir_path, vbDirectory) = "" Then
    30.                     ' The directory doesn't exist.
    31.                     ' Make it.
    32.                     MkDir dir_path
    33.                 End If
    34.             End If
    35.         End If
    36.     Next i
    37. 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

  19. #19
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  20. #20

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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

  21. #21

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by Nightwalker83 View Post
    I replied to the above thread hopefully someone can point me in the right direction.
    Here is the solution:

    Quote Originally Posted by jpbro View Post
    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

  22. #22
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  23. #23

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    Like so:

    vb Code:
    1. 'Source: http://social.msdn.microsoft.com/Forums/en/vbide/thread/395b12fd-ccfc-4281-b1b3-4c69b56f8b85
    2. Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
    3.  
    4. Public Type OSVERSIONINFO
    5.     dwOSVersionInfoSize As Long
    6.     dwMajorVersion As Long
    7.     dwMinorVersion As Long
    8.     dwBuildNumber As Long
    9.     dwPlatformId As Long
    10.     szCSDVersion As String * 128
    11. End Type
    12.  
    13. Procedure :-
    14.  
    15. Private Sub WinVersion()
    16.     Dim osinfo As OSVERSIONINFO
    17.     Dim retvalue As Integer
    18.    
    19.     osinfo.dwOSVersionInfoSize = 148
    20.     osinfo.szCSDVersion = Space$(128)
    21.     retvalue = GetVersionExA(osinfo)
    22.  
    23.     If osinfo.dwMajorVersion = 6 Then 'Vista
    24.     ElseIf osinfo.dwMajorVersion = 5 Then 'XP
    25.     ElseIf osinfo.dwMajorVersion = 4 Then 'Win2k etc.
    26.     Else
    27.     End If
    28. 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

  24. #24
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  25. #25

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by jmsrickland View Post
    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:
    1. Private Sub WinVersion()
    2. 'Retrieve the current operating system and set the settings path accordingly
    3. 'http://social.msdn.microsoft.com/Forums/en/vbide/thread/395b12fd-ccfc-4281-b1b3-4c69b56f8b85
    4.     Dim osinfo As OSVERSIONINFO
    5.     Dim retvalue As Integer
    6.     Dim sNextFile As String
    7.     osinfo.dwOSVersionInfoSize = 148
    8.     osinfo.szCSDVersion = Space$(128)
    9.     retvalue = GetVersionExA(osinfo)
    10.     If osinfo.dwMajorVersion = 7 Then 'Windows 7
    11.    If Not Dir$(App.Path & "\xlive.dll") <> "" Then
    12.     Path = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
    13.     'source = path
    14.     Else
    15.     Path = GetSpecialfolder(SpecialFolders.MyDocuments) & "\Rockstar Games\GTA IV\savegames\"
    16.     'destination = path
    17.     End If
    18.     ElseIf osinfo.dwMajorVersion = 6 Then 'Vista
    19.     If Not Dir$(App.Path & "\xlive.dll") <> "" Then
    20.    
    21.     Path = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
    22.      'source = path
    23.       Else
    24.       Path = GetSpecialfolder(SpecialFolders.MyDocuments) & "\Rockstar Games\GTA IV\savegames\"
    25.      'destination = path
    26.     End If
    27.     ElseIf osinfo.dwMajorVersion = 5 Then 'XP
    28.     If Not Dir$(App.Path & "\xlive.dll") <> "" Then
    29.     Path = GetSpecialfolder(SpecialFolders.Drives) & sUserName & "\" & GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
    30.      'source = path
    31.     Else
    32.     Path = "C:\Users\" & sUserName & "\" & GetSpecialfolder(SpecialFolders.MyDocuments) & "Rockstar Games\GTA IV\savegames\"
    33.      'destination = path
    34.     End If
    35.     'ElseIf osinfo.dwMajorVersion = 4 Then 'Win2k etc.
    36.     Else
    37.     End If
    38.     'copy
    39.     'Delete (Path)
    40. 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

  26. #26
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  27. #27

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by jmsrickland View Post
    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

  28. #28
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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,...

  29. #29

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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

  30. #30
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    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

  31. #31

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by MarkT View Post
    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:
    1. Private Sub WinVersion()
    2. 'Retrieve the current operating system and set the settings path accordingly
    3. 'http://social.msdn.microsoft.com/Forums/en/vbide/thread/395b12fd-ccfc-4281-b1b3-4c69b56f8b85
    4.     Dim osinfo As OSVERSIONINFO
    5.     Dim retvalue As Integer
    6.     Dim sNextFile As String
    7.     osinfo.dwOSVersionInfoSize = 148
    8.     osinfo.szCSDVersion = Space$(128)
    9.     retvalue = GetVersionExA(osinfo)
    10.     If osinfo.dwMajorVersion = 7 Then 'Windows 7
    11.    If Not FileExists(App.Path & "\xlive.dll") Then
    12.       source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\"
    13.       destination = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
    14.       Else
    15.       source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
    16.       destination = GetSpecialfolder(SpecialFolders.MyDocuments) & "\Rockstar Games\GTA IV\savegames\"
    17.     End If
    18.     ElseIf osinfo.dwMajorVersion = 6 Then 'Vista
    19.     If Not FileExists(App.Path & "\xlive.dll") Then
    20.       source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\"
    21.       destination = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
    22.       Else
    23.       source = "\Rockstar Games\GTA IV\Settings\"
    24.       destination = "c:\Rockstar Games\GTA IV\savegames\"
    25.       'GetSpecialfolder(SpecialFolders.Local_AppData) &
    26.       'GetSpecialfolder(SpecialFolders.MyDocuments) &
    27.     End If
    28.     ElseIf osinfo.dwMajorVersion = 5 Then 'XP
    29.     If Not FileExists(App.Path & "\xlive.dll") Then
    30.     source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\"
    31.     destination = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
    32.     Else
    33.     source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\"
    34.     destination = GetSpecialfolder(SpecialFolders.MyDocuments) & "Rockstar Games\GTA IV\savegames\"
    35.     End If
    36.     'ElseIf osinfo.dwMajorVersion = 4 Then 'Win2k etc.
    37.     Else
    38.     End If
    39.      'Call Delete(source)
    40.     'http://www.vbforums.com/showthread.php?t=641462&highlight=copy+folder
    41.      Call VBCopyFolder(source, destination)
    42.      Call Copy(source)
    43. End Sub
    44.  
    45. Private Sub Copy(source)
    46. Dim c As String
    47. c = source + "\savegames\user_e00006645743f1a9\"
    48. sNextFile = Dir$(c + "*.*", vbNormal + vbHidden + vbReadOnly)
    49. Do While sNextFile <> ""
    50.      SetAttr c & sNextFile, vbNormal
    51.      FileCopy c, destination
    52.      sNextFile = Dir$
    53. Loop
    54. 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

  32. #32
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by Nightwalker83 View Post
    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.

  33. #33

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by MarkT View Post
    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

  34. #34

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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

  35. #35
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    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.

  36. #36

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by MarkT View Post
    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

  37. #37
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  38. #38
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Retrieve both the source and destination when they are either side of an if state

    Quote Originally Posted by Nightwalker83 View Post
    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:
    1. Private Sub WinVersion()
    2.     'Retrieve the current operating system and set the settings path accordingly
    3.     'http://social.msdn.microsoft.com/Forums/en/vbide/thread/395b12fd-ccfc-4281-b1b3-4c69b56f8b85
    4.     Dim osinfo As OSVERSIONINFO
    5.     Dim retvalue As Integer
    6.     Dim sNextFile As String
    7.     osinfo.dwOSVersionInfoSize = 148
    8.     osinfo.szCSDVersion = Space$(128)
    9.     retvalue = GetVersionExA(osinfo)
    10.     If osinfo.dwMajorVersion = 7 Then 'Windows 7
    11.         If Not FileExists(App.Path & "\xlive.dll") Then
    12.             source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\"
    13.             destination = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
    14.         Else
    15.             source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
    16.             destination = GetSpecialfolder(SpecialFolders.MyDocuments) & "\Rockstar Games\GTA IV\savegames\"
    17.         End If
    18.     ElseIf osinfo.dwMajorVersion = 6 Then 'Vista
    19.         If Not FileExists(App.Path & "\xlive.dll") Then
    20.             source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\"
    21.             destination = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
    22.         Else
    23.             source = "\Rockstar Games\GTA IV\Settings\"
    24.             destination = "c:\Rockstar Games\GTA IV\savegames\"
    25.             'GetSpecialfolder(SpecialFolders.Local_AppData) &
    26.             'GetSpecialfolder(SpecialFolders.MyDocuments) &
    27.         End If
    28.     ElseIf osinfo.dwMajorVersion = 5 Then 'XP
    29.         If Not FileExists(App.Path & "\xlive.dll") Then
    30.             source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\"
    31.             destination = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\Settings\"
    32.         Else
    33.             source = GetSpecialfolder(SpecialFolders.Local_AppData) & "\Rockstar Games\GTA IV\"
    34.             destination = GetSpecialfolder(SpecialFolders.MyDocuments) & "Rockstar Games\GTA IV\savegames\"
    35.         End If
    36.     'ElseIf osinfo.dwMajorVersion = 4 Then 'Win2k etc.
    37.     Else
    38.     End If
    39.     'Call Delete(source)
    40.     'http://www.vbforums.com/showthread.php?t=641462&highlight=copy+folder
    41.     Call VBCopyFolder(source, destination)
    42.     Call Copy(source)
    43. End Sub
    44.  
    45. Private Sub Copy(source)
    46.     Dim c As String
    47.     c = source + "\savegames\user_e00006645743f1a9\"
    48.     sNextFile = Dir$(c + "*.*", vbNormal + vbHidden + vbReadOnly)
    49.     Do While sNextFile <> ""
    50.          SetAttr c & sNextFile, vbNormal
    51.          FileCopy c, destination
    52.          sNextFile = Dir$
    53.     Loop
    54. 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

  39. #39

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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:
    1. Private Function GetPath()
    2.     If Not Dir$(App.Path & "\xlive.dll") <> "" Then
    3.         source = GetSpecialFolder(CSIDL_LOCAL_APPDATA) & "\Rockstar Games\GTA IV\"
    4.         destination = GetSpecialFolder(CSIDL_LOCAL_APPDATA) & "\Rockstar Games\GTA IV\"
    5.     Else
    6.         source = GetSpecialFolder(CSIDL_LOCAL_APPDATA) & "\Rockstar Games\GTA IV\"
    7.          destination = GetSpecialFolder(CSIDL_PERSONAL) & "\Rockstar Games\GTA IV\"
    8.     End If
    9.      Call Copy(source)
    10. End Function
    11.  
    12. Private Sub Copy(source)
    13. Dim c As String
    14. c = source & "savegames\user_e00006645743f1a9"
    15. destination = destination & "savegames\user_e00006645743f1a9"
    16. Call VBCopyFolder(c, destination)
    17. End Sub

    I am using the above code in conjunction with the code I linked to in post #31.

    Edit:

    Quote Originally Posted by Spoo View Post
    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
  •  



Click Here to Expand Forum to Full Width