How to get programmatically the number of AppData\Roaming\SDL\ProjectApi folder?

I'm checking Studio 2019 SR2 and found that my code for getting the real default project template is failing...
It's failing because Studio 2019 screwed the folders numbering system which worked for years... Disappointed

So far the numbering system was simple and consistent:

    "Studio2"  {$StudioVersionAppData = "10.0.0.0"}
    "Studio3"  {$StudioVersionAppData = "11.0.0.0"}
    "Studio4"  {$StudioVersionAppData = "12.0.0.0"}
    "Studio5"  {$StudioVersionAppData = "14.0.0.0"}
    "Studio15" {$StudioVersionAppData = "15.0.0.0"}

But now I see that Studio 2019 SR1 - and also SR2 - has AppData\Roaming\SDL\ProjectApi\15.1.0.0 folder :-O :-O :-O

That number does not correspond to anything...
All other such numbered folders have 15.0.0.0 number.
SDLTradosStudio.exe product version is 15.0.0.0, file version is 15.2.0.1041.

So, where does this weird number come from and how do I get it programmatically, please?!
Of course I need it to work 100% realiably across ALL Studio versions, SRs and CUs.

Ultimately, I need to read the AppData\Roaming\ProjectApi\<number>\Sdl.ProjectApi.xml file, so if there is any other way to get its full path, I'm fine with that way too.

Parents
  • Hello ,

    I did a fix for this problem in one of our application named SdlFreshstart. You can check the below print screen of the code on how I tooked the correct folder version. The code is also avaiable, on our Sdl Community Github repository: https://github.com/sdl/Sdl-Community/tree/master/SdlFreshstart/Sdl.Community.SdlFreshstart

    Screenshot of Visual Studio code editor displaying a method to get the last ProjectApiPath folder version from SdlFreshstart application.

    With kind regards,

    Florentina Caputa

    With kind regards,

    Florentina Caputa



    Generated Image Alt-Text
    [edited by: Trados AI at 1:19 PM (GMT 0) on 5 Mar 2024]
  • Hmmm, at the first glance this does not seem to be reliable enough.
    Relying on a directory timestamp is very unsafe. Anything in the system can change the timestamp of directories (even the filesystem itself), so this is not the way to go.

    I'm trying a different approach now...

    In fact my real ultimate goal is to get the path to a project template currently selected as default in Studio.
    So I get the template GUID from the user settings and then I need to get the path to the local projects directory, to read the projects.xml(?) file to find the template with this GUID.
    And so far the way was to get the path from this Sdl.ProjectApi.xml file.

    But I found that there is a way to get the local project directory path programmatically - .NET Reflector is really a good friend - so I'm now experimenting with this way.
    (I don't have more details right now as I'm not at the machine with Studio and the code)

    EDIT:
    Sdl.ProjectApi.dll contains Sdl.ProjectApi.ApplicationFactory class. The CreateApplication() constructor creates application object which has a LocalProjectServers property. It's an array, but since to my best knowledge Studio can have only single local project server, I simply take the first element and get its ProjectTemplates property - this is an array of defined project templates, so I then take the one with the right GUID.
    Ufffff...

Reply
  • Hmmm, at the first glance this does not seem to be reliable enough.
    Relying on a directory timestamp is very unsafe. Anything in the system can change the timestamp of directories (even the filesystem itself), so this is not the way to go.

    I'm trying a different approach now...

    In fact my real ultimate goal is to get the path to a project template currently selected as default in Studio.
    So I get the template GUID from the user settings and then I need to get the path to the local projects directory, to read the projects.xml(?) file to find the template with this GUID.
    And so far the way was to get the path from this Sdl.ProjectApi.xml file.

    But I found that there is a way to get the local project directory path programmatically - .NET Reflector is really a good friend - so I'm now experimenting with this way.
    (I don't have more details right now as I'm not at the machine with Studio and the code)

    EDIT:
    Sdl.ProjectApi.dll contains Sdl.ProjectApi.ApplicationFactory class. The CreateApplication() constructor creates application object which has a LocalProjectServers property. It's an array, but since to my best knowledge Studio can have only single local project server, I simply take the first element and get its ProjectTemplates property - this is an array of defined project templates, so I then take the one with the right GUID.
    Ufffff...

Children
No Data