C# Add File Selected using OpenFileDialog1 to Resources

Discussion in 'Computer Programming, Emulation, and Game Modding' started by DavidRO99, Jul 18, 2016.

  1. DavidRO99
    OP

    DavidRO99 Official depressed pikachu

    Member
    964
    267
    Jun 11, 2016
    Korea, North
    your back-door
    So, if you check the PS3 Forums you may see that I made a mod menu named Project FaZe. That mod menu also has a custom program. The problem is that I made the custom program in such a way that it contains the actual mod menu inside the Resources and I would like to make a way to add any mod menu file to Resources using OpenFileDialog1. Easy just throw some code together and... error. Can any of you talented people help me find the error?

    Code:
    private void materialFlatButton4_Click_1(object sender, EventArgs e)
        {
            openFileDialog1.Title = "Open GSC File";
            openFileDialog1.Filter = "GSC|*.gsc";
            string fileName = "_development_dvars.gsc";
            fileName = openFileDialog1.FileName;
            openFileDialog1.FileName = "";
            openFileDialog1.InitialDirectory =     System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog1.ShowDialog();
            openFileDialog1.FileName = Project_FaZe_Injector.Properties.Resources._development_dvars;
        }
     
  2. BeySW

    BeySW Newbie

    Newcomer
    1
    0
    Jul 28, 2016
    United States
    Oklahoma
    To begin, the code sets the filename and then clears it.
    Anyway, try this, though I'm not too sure what you are trying to do.
    The code is very well commented.

    Code:
    private static void materialFlatButton4_Click_1(object sender, EventArgs e)
    {
        // Prompt user to open file
        OpenFileDialog open = new OpenFileDialog
        {
            Title = "Open GSC File",
            Filter = "GSC|*.gsc",
            FileName = "_development_dvars.gsc"
        };
    
        // If user clicks cancel, return.
        if (open.ShowDialog() != DialogResult.OK)
            return;
    
        // As the file is an embedded resource, extract it to the Windows %TEMP% directory.
        string fileName = Path.GetTempPath() + "_development_dvars.gsc"; // Full path & file name.
        byte[] developmentDvars = Resources._development_dvars;  // Extract resource file.
        File.WriteAllBytes(fileName, developmentDvars);  // Copy it as a file to the temp directory.
    
        // we know the above created our file but we check, just in case.
        if (File.Exists(open.FileName))
        {
            // At this point, the file is open.
            // TODO: Process file here..
        }
    }
    
     
  3. DavidRO99
    OP

    DavidRO99 Official depressed pikachu

    Member
    964
    267
    Jun 11, 2016
    Korea, North
    your back-door
    Im trying to copy the file that the user selected to the Resources of the application :) You are doing the exact opposite
     
  4. evandixon

    evandixon PMD Researcher

    Member
    1,655
    781
    May 29, 2009
    United States
    Resources are generally read-only. If you want to change them, it would be best to store them elsewhere. Perhaps copy from the resources to the Current User App Data if the file doesn't exist there, and have your dialog alter the resources there?
     
  5. DavidRO99
    OP

    DavidRO99 Official depressed pikachu

    Member
    964
    267
    Jun 11, 2016
    Korea, North
    your back-door
    The problem is that I don't know how to make a custom resources file so it can read from a folder that I would include with the exe