0

I used innosetup to install my application. All the files for example are in program files\test In the directory i have the exe file of my program and also ffmpeg.exe

Now in my code i did :

class Ffmpeg
    {
        NamedPipeServerStream p;
        String pipename = "mytestpipe";
        byte[] b;
        System.Diagnostics.Process process;
        string ffmpegFileName;
        string workingDirectory;

        public Ffmpeg()
        {
            workingDirectory = Path.GetDirectoryName(Application.LocalUserAppDataPath) + @"\workingDirectory";
            ffmpegFileName = @"\ffmpeg.exe";
            if (!Directory.Exists(workingDirectory))
            {
                Directory.CreateDirectory(workingDirectory);
            }
            ffmpegFileName = workingDirectory + ffmpegFileName;
            Logger.Write("Ffmpeg Working Directory: " + ffmpegFileName);
        }

        public void Start(string pathFileName, int BitmapRate)
        {
            try
            {
                string outPath = pathFileName;
                Logger.Write("Output Video File Directory: " + outPath);
                Logger.Write("Frame Rate: " + BitmapRate.ToString());
                p = new NamedPipeServerStream(pipename, PipeDirection.Out, 1, PipeTransmissionMode.Byte);
                b = new byte[1920 * 1080 * 3]; // some buffer for the r g and b of pixels of an image of size 720p

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.WindowStyle = ProcessWindowStyle.Hidden;
                psi.UseShellExecute = false;
                psi.CreateNoWindow = true;
                psi.FileName = ffmpegFileName;
                psi.WorkingDirectory = workingDirectory;

Thep roblem is that the directory workingDirectory not contain the ffmpeg.exe after installation . so if the user will run first time the program after installation the file will be missing .

I added the ffmpeg.exe to my project and set it to : Content and Copy always

What i want to do is that somehow to set the workingDirectory to the place where the user was installing the program if it's program file or any other directory .

Or to set the workigDirectory to the file ffmpeg.exe i already added to the project.

The problem is after installation the user will run the program and the directory workingDirectory will be empty .

joneK
  • 241
  • 1
  • 4
  • 13
  • So setup a registry key during installation for the path which the user has selected for installation. Read that path in your application – ata Jun 08 '13 at 21:23
  • I think you didn't create your Installation package correctly. A working installation package would be so complete that user has to do nothing. After installing, there is some shortcut in Start menu and that's where your user can find how to run your application. – King King Jun 08 '13 at 21:28

3 Answers3

1

if the file ffmpeg.exe is installed in the same directory where the assembly that calls it resides, then your could write:

string fullPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string installDirectory = Path.GetDirectoryName( fullPath );

However if you really want to copy that file from the installed directory to the Application.LocalUserAppDataPath

// Assuming that the LocalUserAppDataPath has already been created
string destDirectory = Path.Combine(Application.LocalUserAppDataPath, "workingDirectory");
File.Copy(Path.Combine(installDirectory, "ffmpeg.exe"), 
          Path.Combine(destDirectory, "ffmpeg.exe"), true);

but then, why you don't search the functionality of InnoSetup to discover how to place the ffmpeg.exe file in the workingDirectory during setup? That will solve all your issues here.

Steve
  • 213,761
  • 22
  • 232
  • 286
  • I think he wants to place his `ffmpeg.exe` in the folder `Path.GetDirectoryName(Application.LocalUserAppDataPath) + @"\workingDirectory"` – King King Jun 08 '13 at 21:30
  • if it is in the same folder with the main .exe, that's so simple. – King King Jun 08 '13 at 21:31
  • Well I think that the OP should clarify this point because it is very confusing. – Steve Jun 08 '13 at 21:35
  • I agree, it's so confusing. He should express the problem in another way clearer, don't need too much code as he posted. – King King Jun 08 '13 at 21:38
  • but then, why he hasn't copied it in the correct place during installation?. I don't know InnoSetup but I think that program has all the functionalities to copy a file in an arbitrary path – Steve Jun 08 '13 at 21:55
  • that's also my thought, his setup project (or setup software) should do it for him (setup everything). I guess the standard Visual Studio Setup project can do that. – King King Jun 08 '13 at 21:59
0

You can use Application.StartupPath to reference the folder path where are your main executable and ffmpeg.exe

Application.StartupPath

Gets the path for the executable file that started the application, not including the executable name.

http://msdn.microsoft.com/en-us/library/system.windows.forms.application.startuppath.aspx

And then if you need it... copy the ffmpeg.exe to the working directory that you choose.. though I think its not a good idea...

 File.Copy(Source, Target)

http://msdn.microsoft.com/en-us/library/c6cfw35a.aspx

string destDirectory = Path.Combine(Application.LocalUserAppDataPath, "workingDirectory");
string ffmpegDestPath = Path.Combine(destDirectory, "ffmpeg.exe");
string ffmpegSrcPath = Path.Combine(Application.StartupPath, "ffmpeg.exe");

if (!File.Exist(ffmpegDestPath)) {
     if (!Directory.Exists(destDirectory)) Directory.Create(destDirectory);
     File.Copy(ffmpegSrcPath , ffmpegDestPath );
}
Blau
  • 5,742
  • 1
  • 18
  • 27
  • I don't think that is what the OP wants. His `ffmpeg.exe` file should be located in the folder `Path.GetDirectoryName(Application.LocalUserAppDataPath) + @"\workingDirectory"` – King King Jun 08 '13 at 21:32
  • I think he wants to place his `ffmpeg.exe` in that folder but his Installation package doesn't move `ffmpeg.exe` to that folder and that's why it's empty. So the problem is how to move it to that folder when installing. I think you underestimated the problem here. – King King Jun 08 '13 at 21:34
  • but it is not needed... ffmpeg should be in that application path... in the AplicationDataPath he should store only data not apps – Blau Jun 08 '13 at 21:35
  • yes, if I were him, I also would like to place it in the same folder (or a relative folder) with the main app path. But that's his want. :) – King King Jun 08 '13 at 21:36
  • and by the way he only need to copy ffmpeg.exe from Application.StartupPath to Application.LocalUserAppData using File.Copy(source, target) – Blau Jun 08 '13 at 21:36
  • Blau but how the program will know to copy the ffmpeg.exe to the applicationdatapath ? I can copy now the file to this directory but when the user run the program the file is not there . The ffmpeg.exe is in the installed directory of the program in program files . The directory workingDirectory is created after the user run the program first time and if i want to copy the ffmpeg.exe to the applicationdatapath i need to copy it from the installed directory . I cant figure it out . – joneK Jun 08 '13 at 21:55
  • Blau how do you copy the ffmpeg.exe fromo ne directory to another ? – joneK Jun 08 '13 at 21:56
  • when you run the application you should check if file ffmpeg.exe exists in the working directory, if not then you have the files ffmpeg and application executable together, so is easy to copy ffmpeg.exe from the application directory to the working directory – Blau Jun 09 '13 at 09:31
  • are you sure that you need ffmpeg.exe in the user working directory? command line tools usually accept destination directories as arguments – Blau Jun 09 '13 at 09:38
0

1- You should create a registry key that can store the installation path and path of any other folder that your application needs. Check this question on how to do that: How to write install path to registry after install is complete with Inno setup

2- Read the registry settings at application startup. Use those paths.

Community
  • 1
  • 1
ata
  • 8,853
  • 8
  • 42
  • 68
  • His problem is not what the path is, he already knows beforehand the path `Path.GetDirectoryName(Application.LocalUserAppDataPath) + @"\workingDirectory"` because that's path is a common path which does exist in Windows OS (the subfolder `workingDirectory` is created by his app). His problem is there is not `ffmpeg.exe` in that folder. As I said, it involves the Installation project. That's the work of the installation project. – King King Jun 08 '13 at 21:55
  • King King ok you are right so i need to tell the installation program InnoSetup to create the directory i want for example workingDirectory somewhere and then to copy the ffmpeg.exe to this directory while installing right ? – joneK Jun 08 '13 at 21:58
  • @joneK yes, That's what you have to try understanding, finding out how to do that. If using Visual Studio Setup Project, I can help. But for your `innoSetup`, I can't. – King King Jun 08 '13 at 22:02
  • Kink King the visual studio setup is very basic no ? I have visual studio 2012 pro could you show me step by step how to do it with the files and how to add files icons stuff ? For some reason when i select publish in my application properties i have a wizard with very limited options . – joneK Jun 08 '13 at 22:37
  • ok.maybe try this question: http://stackoverflow.com/questions/13537071/inno-setup-how-to-copy-a-file-before-setup-start – ata Jun 09 '13 at 11:09