1

i write desktop app in C# .... this app will auto generate an C/C++ code for an embededd system project
so i have to copy some pre_writen drivers to the target folder (where the file is generated)

the problem is i don't know where i can correctly put the sourc driver in !!

for now i put the source driver in in the project foldr and i refrance it in my code lik

            // projectfolder\bin\Debug\netcoreapp3.1\file.exe
            string path = (Assembly.GetExecutingAssembly().Location);
            DirectoryInfo exeDir = new DirectoryInfo(path);
            DirectoryInfo projectDir = exeDir.Parent.Parent.Parent.Parent;
            // now i can get the driver foler like this
            string DriverPath = Path.Combine(projectDir.fullName,"drivers");

i guss that folder in the product level will be in C:\ProgramData but for developing where the location shoud be in ?

Ibram Reda
  • 1,882
  • 2
  • 7
  • 18

3 Answers3

0

The default location in a c# dekstop app in Environment.CurrentDirectory + "\\Folder"

  • Environment.CurrentDirectory will return the directory location of the .exe (projectfolderDir+\bin\Debug\netcoreapp3.1) but my qustion was where the correct place to add the surce Device Driver folder ? – Ibram Reda Feb 01 '20 at 12:25
  • You mean when you install your program on another machine ? – Aboubacar Traore Feb 01 '20 at 12:56
0

This is mostly a question of how often the data will change. And how that will interact with the very strict management of write rights since NTFS became common (While the rule predates NTFS, with mostly FAT - and thus no rights to stop us - few programmers cared).

You can and even should put stuff into the Programm directory itself, if it does not change outside of Programm Updates/Reinstallations. If it only changes with a Installer or Updater - things that need administrative rights for their work anyway - it belong there.

If changes happen more often then that - especially stuff that can change at runtime or even needs to change at runtime - where the programm folder becomes unuseable. In this case the programm directory should at tops include a template file. Something you can copy to the real directory as a baseline, to have something to start working with. As for where to put this changeable data, look at the SpecialFolders Enumeration. The Userprofile - particulary Appdata folders are the point to look at. Wich specific one to use is a question of how you want it to interact with Domain Controler Synchronisation (Roaming vs non-Roaming user). Or if you want it to end up in Common.

Drivers sound like that rare case, where the programm directory is entirely fitting. Optionally you could have the drivers installed as a parallel application. Something that can be managed/updated seperately and is simply a requirement for your programm. Something that might be shared across multiple applications.

Christopher
  • 9,634
  • 2
  • 17
  • 31
  • first of all thanks for replying ...i guss you miss understand me ... my driveres is a folder with plain cpp files wich has no interaction with my C# app . but it must be in the the output folder.. so i need to copy the folder as it is in same directory with my generated file . i don't know the correct place to locate this folder to copy it (copy as it is) in the output folder .the way i use i feel it is wrong because it refrance .exe directory and then go reletivley to the driver folder as showen above. if you can suggest the correct way to locate and refrance my folder that will be grate – Ibram Reda Feb 01 '20 at 13:32
  • @IbramReda It is possible to reference a Folder in a Project and have it as-is copied to the output directory. Rather then a bunch of loose files. Afaik "copy to output" a whole directory is the only way to get a folder structure | These folders can even be weakly linked to your project - there is only one actuall source folder on the disk - and not nessesarily in any Projects structure either - that multiple Projects reference. But they each create a *current copy* in of it the output directory when you build. – Christopher Feb 01 '20 at 14:09
0

In Windows there are different types of data that may be consumed by an Application such as

  • Application Properties

    Application settings enable you to store application information dynamically. Settings allow you to store information on the client computer that should not be included in the application code.

    Ex: Position, Font, Styles, User Configuration
    File Type: App.Config(Is created at design time and is by default put into BIN folder) and User.Config (Created at run time)
    Project > Add New Item > Installed > Visual C# Items > Application Configuration File


  • Application Data

    Contains all the data, settings, and user files that are required by the installed software and UWP apps. These are user agnostic data.

    Ex: Images, Resources, Sprites, Data Templates, txt files. It may also contain App.Config files

    File Location: C:\ProgramData Environment.SpecialFolder.CommonAppData


  • User Data

    Contain all data that is user specifc, such as his/her app specific settings.

    Ex: Any type of data

    File Location: C:\Users\[USERNAME]\AppData\Roaming Environment.SpecialFolder.AppData or Environment.SpecialFolder.MyDocuments


i guss that folder in the product level will be in C:\ProgramData but for developing where the location shoud be in ?

yes, it will go to ProgramData, but during the development you can have it in your BIN folder or a directory of your choice if it matters

However most of the above will come into picture when you package your App to an MSI and bundle in all the dependency files and where they need to go.



EDIT

Based on the OPs clarification in comments, .CPP files will automatically go into the BIN/Debug Folder of your C# app.
You will need to dynamically place your device drives in the directory where your exe is running

To access the directory where your app is running :

string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location Output of Path = Absolute path where your exe is running C:\Users\User1\source\repos\Test\Test\bin\Debug\Test.exe

string exeDirectory = Path.GetDirectoryName(exePath); The Directory path where your exe is situated C:\Users\User1\source\repos\Test\Test\bin\Debug

Clint
  • 6,011
  • 1
  • 21
  • 28