Thread: Making a setup which would generate some folders with the files needed for program.

  1. #1
    Registered User
    Join Date
    Feb 2018
    Posts
    8

    Making a setup which would generate some folders with the files needed for program.

    Hi there.
    I was wondering if you could help me with some information. I think it is simple, but I'm still novice.

    The thing is. The program loads 39 pics from 2 folders, the program just shows them and also i have there some buttons but that the button doesn't matter. As i said, the program load the pics from 2 folders, which are located in my computer ( c:\desktop\ etc.. ). In the code in a specific variable is the location -> mPicPath = "C:/Users/sasam/Desktop/POO/geo/photoss/init";. Ok, it works fine, but I want to use this program in another computer, and here is the problem. In the code i have just my address, another computer will not have the same address as my computer does, so it would not know where to load the pics from. And even i have to move the two folders with the exe everywhere. I think my point is clear.
    Can I make an install which would generate the folders with the pics in them and automatically readjust to a given address ( in the code ).

    Any infos would be helpful. Thank you.

    The code - ( i will highlight the address variable )

    Code:
    #pragma once
    
    
    namespace speranta {
    
    
        using namespace System;
        using namespace System::ComponentModel;
        using namespace System::Collections::Generic;
        using namespace System::Windows::Forms;
        using namespace System::Data;
        using namespace System::IO;
        using namespace System::Drawing;
    
    
        /// <summary>
        /// Summary for MyForm
        /// </summary>
        int norep[100]; 
        int l = 1;
        
        public ref class MyForm : public System::Windows::Forms::Form
        {
            String^ mPicPath;
            List<String^> ^mPicNames;
            Random^ mRandom;
            // second folder
            String^ mPicPath2;
                 List<String^> ^mPicNames2;
        public:
            MyForm(void)
            {
                InitializeComponent();
            }
    
    
        protected:
            /// <summary>
            /// </summary>
            ~MyForm()
            {
                if (components)
                {
                    delete components;
                }
            }
        private: System::Windows::Forms::PictureBox^  pictureBox1;
        protected:
        private: System::Windows::Forms::Button^  button1;
        private: System::Windows::Forms::Button^  button2;
        private:
            /// <summary>
            /// </summary>
            System::ComponentModel::Container ^components;
    
    
    #pragma region Windows Form Designer generated code
            /// <summary>
            /// </summary>
            void InitializeComponent(void)
            {
                this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
                this->button1 = (gcnew System::Windows::Forms::Button());
                this->button2 = (gcnew System::Windows::Forms::Button());
                (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
                this->SuspendLayout();
                // 
                // pictureBox1
                // 
                this->pictureBox1->Location = System::Drawing::Point(12, 12);
                this->pictureBox1->Name = L"pictureBox1";
                this->pictureBox1->Size = System::Drawing::Size(1057, 617);
                this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
                this->pictureBox1->TabIndex = 0;
                this->pictureBox1->TabStop = false;
                this->pictureBox1->Click += gcnew System::EventHandler(this, &MyForm::pictureBox1_Click);
                // 
                // button1
                // 
                this->button1->Location = System::Drawing::Point(306, 635);
                this->button1->Name = L"button1";
                this->button1->Size = System::Drawing::Size(187, 32);
                this->button1->TabIndex = 1;
                this->button1->Text = L"Genereaza";
                this->button1->UseVisualStyleBackColor = true;
                this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
                // 
                // button2
                // 
                this->button2->Location = System::Drawing::Point(581, 635);
                this->button2->Name = L"button2";
                this->button2->Size = System::Drawing::Size(187, 32);
                this->button2->TabIndex = 2;
                this->button2->Text = L"Rezultat";
                this->button2->UseVisualStyleBackColor = true;
                this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
                // 
                // MyForm
                // 
                this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
                this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                this->ClientSize = System::Drawing::Size(1081, 672);
                this->Controls->Add(this->button2);
                this->Controls->Add(this->button1);
                this->Controls->Add(this->pictureBox1);
                this->Name = L"MyForm";
                this->Text = L"MyForm";
                this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
                (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
                this->ResumeLayout(false);
    
    
            }
    #pragma endregion
    
    
        private: System::Void pictureBox1_Click(System::Object^  sender, System::EventArgs^  e) {
            //------
        }
                 int f;
        public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
        {
            int k = 0;
            int idx = mRandom->Next(mPicNames->Count);
            do {
                if ((l == 39) || (l==40)) {
                    for (int i = 0; i <= 40; i++) norep[i] = 0;
                }
                k = 0;
                for (int i = l; i > 0; i--)
                    if (idx != norep[i]) k = k + 1;
                if (k == l)
                {
                    norep[l] = idx;
                    pictureBox1->Image = Image::FromFile(mPicNames[idx]);
                    f = idx;
                    l++;
                    break;
                }
                if (k != l) {
                    idx = mRandom->Next(mPicNames->Count);
                }
            } while (k != l);
        }
    
    
        public: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e)
        {
            pictureBox1->Image = Image::FromFile(mPicNames2[f]);
        }
        private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
            norep[0] = 0;
            for (int q = 0; q <= 100; q++) norep[q] = 0;
            // rezultat
            mPicPath2 = "C:/Users/sasam/Desktop/POO/geo/photoss/rezult";
            mPicNames2 = gcnew List<String^>;
            array<String^> ^tmp2 = Directory::GetFiles(mPicPath2, "*.png");
            mPicNames2->AddRange(tmp2);
            tmp2 = Directory::GetFiles(mPicPath2, "*.jpg");
            mPicNames2->AddRange(tmp2);
            if (mPicNames2->Count == 0)
            {
                MessageBox::Show("Nici o imagine adaugata");
                return;
            }
            pictureBox1->Image = Image::FromFile(mPicNames2[0]);
    
    
            // resurse
    
            mPicPath = "C:/Users/sasam/Desktop/POO/geo/photoss/init";
            mPicNames = gcnew List<String^>;
            array<String^> ^tmp = Directory::GetFiles(mPicPath, "*.png");
            mPicNames->AddRange(tmp);
            tmp = Directory::GetFiles(mPicPath, "*.jpg");
            mPicNames->AddRange(tmp);
            if (mPicNames->Count == 0)
            {
                MessageBox::Show("Nici o imagine adaugata");
                return;
            }
            mRandom = gcnew Random();
            pictureBox1->Image = Image::FromFile(mPicNames[0]);
        }
    };
    }
    Screenshot - 7405bd26b07010e337de74a3a1bfa854 - Gyazo

    photo to get a better idea.
    Last edited by Alex Matei; 04-11-2018 at 10:42 AM.

  2. #2
    Registered User
    Join Date
    Feb 2018
    Posts
    8
    up !!! PLS someone

  3. #3
    Registered User
    Join Date
    Feb 2018
    Posts
    8
    anyone ? help

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    OpenFileDialog Class (System.Windows.Forms)
    So just add a couple of openfiledialogs.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Feb 2018
    Posts
    8
    Quote Originally Posted by Salem View Post
    OpenFileDialog Class (System.Windows.Forms)
    So just add a couple of openfiledialogs.
    I understand. Yes, the open dialog is also an option. But i want that when the program opens, the images to be already there. Not to open a file dialog and select them. That is why I've thought of an install, that will... like generate the .exe and the pics with it. And maybe, in install to select where to put the folder with pics, and that ultimately will became the address where the pics will be loaded (in the code ).

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Some options.

    When you create a shortcut link to your program, there is a field called "Start in", which will be the current directory when the program starts.
    So you could set C:/Users/sasam/Desktop/POO/geo/photoss as your start directory, then try to discover all images below that point.


    You could also do something from the command line, say
    myprog.exe C:/Users/sasam/Desktop/POO/geo/photoss

    Here is where you could do both those things on a shortcut.
    Making a setup which would generate some folders with the files needed for program.-untitled-png
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Feb 2018
    Posts
    8
    Quote Originally Posted by Salem View Post
    Some options.

    When you create a shortcut link to your program, there is a field called "Start in", which will be the current directory when the program starts.
    So you could set C:/Users/sasam/Desktop/POO/geo/photoss as your start directory, then try to discover all images below that point.

    You could also do something from the command line, say
    myprog.exe C:/Users/sasam/Desktop/POO/geo/photoss

    Here is where you could do both those things on a shortcut.
    ----------------

    I will try that.
    Wait, I got something in my mind. Can I get the path of the directory where the program was started. Let's suppose my program is located on C:/Users/sasam/Desktop/prog/ can i get into a variable the current folder automatically.
    Code:
    FolderBrowserDialog^ folder = gcnew FolderBrowserDialog;
        
             folder->ShowDialog();
             String^ FilePathh = folder->SelectedPath;
                 //mPicPath2 = "C:/Users/sasam/Desktop/POO/geo/photoss/rezult";
             mPicPath2 = FilePathh;
    So I've made a folderbrowserdialog. It opens and i select that folder with the pics. Now, maybe is there a properties like SelectedPath, but that will get the current folder where is the program located. Something like rootfolder but that is something else.

    edit -
    I found that folder->rootFolder = Environment::SpecialFolder::Personal; which would go to the my documents directory. So maybe there is a way to get the folder where is the .exe located.
    Last edited by Alex Matei; 04-14-2018 at 04:30 AM.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Yes, a program can find out the current directory.
    Time to rummage through MSDN.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Dec 2010
    Location
    Trinidad, CO (log cabin in middle of nowhere)
    Posts
    148
    You need a setup program. You can actually write them yourself, which is what I do. I would have responded to your question a long time ago if I had C or C++ code to share as an example, but the best I can do is post a PowerBASIC example. PowerBASIC is a low level language like C, but with a lot of high level features like C++. In any case, the most important starting point are various functions exported from shell32.lib that obtain the user's private directories, where, from reading your post, things should go. In the example I'm going to post, the code first calls SHGetFolderPath(), and upon successful completion, the szPath output parameter will contain the null terminated string consisting of the user's path, i.e....

    C:\Users\User_Whoever\Documents

    Then the code below creates various directories and copies various files to those directories. Note I'm not exactly sure of the Windows Api functions one would use in C to do the various things the program below does, such as test whether a directory already exists or not (I guess that's why I have a PowerBAIC example and not a C++ example).

    But I believe the code does the kinds of things you are interested in doing. Like I said, I kind of like writing my own setup programs. Hope this helps.

    Code:
    %Debug        = 1
    %UNICODE      = 1
    #Compile      Exe
    #Dim          All
    #Include Once "Windows.inc"
    #Include Once "ShlObj.inc"
    
    
    Function PBMain() As Long
      Local szTallies As WStringz*128
      Local szPath    As WStringz*128
      Local strReturn As WString
      Local strCurDir As WString
      Local strPath   As WString
      Register i      As Long
      Local fp        As Long
      Local hr        As Long
    
      Console.Screen = 40, 100
      hr=SHGetFolderPath(%NULL,%CSIDL_PERSONAL,%NULL,%SHGFP_TYPE_CURRENT,szPath)
      If SUCCEEDED(hr) Then
         szTallies = szPath & "\Tallies"
         #If %Def(%Debug)
         Con.Print "szPath     = " szPath
         Con.Print "szTallies  = " szTallies
         #EndIf
         strReturn=Dir$(szTallies,%SUBDIR)
         If strReturn="" Then
            #If %Def(%Debug)
            Con.Print szTallies & " Doesn't Exist.  We'll Create It..."
            #EndIf
            MkDir szTallies
         Else
            #If %Def(%Debug)
                Con.Print szTallies & " Already Existed!"
            #EndIf
         End If
         fp=Freefile
         Open szTallies & "\DBConnection.txt" For Output As #fp
         Print #fp,"\\NRFORBOFS02\SIL\SALEDATA.MDB"
         'Print #fp, szTallies & "\DBFILES\SALEDATA.MDB"
         Print #fp, "\\NRFORBOFS02\SIL\SALEDATA.MDB"
         Close #fp
    
         strReturn=Dir$(szTallies & "\DBFiles",%SUBDIR)
         If strReturn="" Then                  ' The C:\Tallies\DBFiles Directory Apparently Doesn't Exist
            #If %Def(%Debug)
            Con.Print szTallies & "\DBFiles" & " Doesn't Exist.  We'll Create It..."
            #EndIf
            MkDir szTallies & "\DBFiles"
            #If %Def(%Debug)
                Con.Print szTallies & "\DBFiles" & " Created!"
            #EndIf
         Else
            #If %Def(%Debug)
                Con.Print szTallies & "\DBFiles" & " Already Existed!"
            #EndIf
         End If
    
         strReturn=Dir$(szTallies & "\Documents",%SUBDIR)
         If strReturn="" Then                  ' The C:\Tallies\Documents Directory Apparently Doesn't Exist
            #If %Def(%Debug)
            Con.Print szTallies & "\Documents" & " Doesn't Exist.  We'll Create It..."
            #EndIf
            MkDir szTallies & "\Documents"
            #If %Def(%Debug)
                Con.Print szTallies & "\Documents" & " Created!"
            #EndIf
         Else
            #If %Def(%Debug)
                Con.Print szTallies & "\Documents" & " Already Existed!"
            #EndIf
         End If
    
         strReturn=Dir$(szTallies & "\RawData",%SUBDIR)
         If strReturn="" Then                  ' The C:\Tallies\RawData Directory Apparently Doesn't Exist
            #If %Def(%Debug)
            Con.Print szTallies & "\RawData" & " Doesn't Exist.  We'll Create It..."
            #EndIf
            MkDir szTallies & "\RawData"
            #If %Def(%Debug)
                Con.Print szTallies & "\RawData" & " Created!"
            #EndIf
         Else
            #If %Def(%Debug)
                Con.Print szTallies & "\RawData" & " Already Existed!"
            #EndIf
         End If
    
         strReturn=Dir$(szTallies & "\TxtFiles",%SUBDIR)
         If strReturn="" Then                  ' The C:\Tallies\TxtFiles Directory Apparently Doesn't Exist
            #If %Def(%Debug)
            Con.Print szTallies & "\TxtFiles" & " Doesn't Exist.  We'll Create It..."
            #EndIf
            MkDir szTallies & "\TxtFiles"
            #If %Def(%Debug)
                Con.Print szTallies & "\TxtFiles" & " Created!"
            #EndIf
         Else
            #If %Def(%Debug)
                Con.Print szTallies & "\TxtFiles" & " Already Existed!"
            #EndIf
         End If
         strCurDir=CurDir$
         Con.Print "strCurDir = " strCurDir
         FileCopy strCurDir & "\TbrBst.exe",  szTallies  & "\TbrBst.exe"
         FileCopy strCurDir & "\FCVols.txt",  szTallies  & "\FCVols.txt"
         FileCopy strCurDir & "\FHGrid9.dll", szTallies  & "\FHGrid9.dll"
         strPath=Environ$("PROGRAMFILES(x86)")
         If strPath="" Then
            Console.Print "strPath=" strPath " Must Be 32 Bit!"
            FileCopy strCurDir & "\dllTally32.dll", szTallies & "\dllTally.dll"
            FileCopy strCurDir & "\Tally32.exe", szTallies & "\Tally32.exe"
            FileCopy strCurDir & "\SaleAdministrationXp.exe", szTallies & "\SaleAdministration.exe"
         Else
            Console.Print "strPath=" strPath " Must Be 64 Bit!"
            FileCopy strCurDir & "\dllTally64.dll", szTallies & "\dllTally.dll"
            FileCopy strCurDir & "\Tally64.exe", szTallies & "\Tally64.exe"
            FileCopy strCurDir & "\SaleAdministrationEx.exe", szTallies & "\SaleAdministration.exe"
         End If
         FileCopy strCurDir & "\Mrk.cfg", szTallies & "\Mrk.cfg"
         FileCopy strCurDir & "\Help.txt", szTallies & "\Help.txt"
         FileCopy strCurDir & "\TbrBst_Cpp_x86.exe", szTallies & "\TB_Cpp_x86.exe"
         FileCopy strCurDir & "\TbrBst_Cpp_x64.exe", szTallies & "\TB_Cpp_x64.exe"
         FileCopy strCurDir & "\FHGrid32.dll", szTallies & "\FHGrid32.dll"
         FileCopy strCurDir & "\FHGrid64.dll", szTallies & "\FHGrid64.dll"
         FileCopy strCurDir & "\SaleData.mdb", szTallies & "\DBFiles\SaleData.mdb"
      End If
      Waitkey$
    
      PBMain=0
    End Function

  10. #10
    Registered User
    Join Date
    Jun 2017
    Posts
    157
    Some other ideas:

    1. embed the images as resources in your .exe file.

    2. deliver the images together with your .exe file

    3. store the images on the web and download them - if you can rely on a internet connection

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making C program read name of files
    By Fedryan in forum C Programming
    Replies: 6
    Last Post: 12-12-2013, 05:10 PM
  2. Making a program delete itself using bat files
    By Danne in forum C++ Programming
    Replies: 8
    Last Post: 02-20-2011, 03:54 AM
  3. Replies: 6
    Last Post: 01-24-2010, 05:53 AM
  4. Problem about making setup project
    By sgh in forum Windows Programming
    Replies: 0
    Last Post: 04-30-2008, 03:09 AM
  5. comparing files and folders
    By vivek_kumbhar in forum C Programming
    Replies: 2
    Last Post: 01-03-2003, 11:30 AM

Tags for this Thread