C# Add File Selected using OpenFileDialog1 to Resources

  • Thread starter Thread starter DavidRO99
  • Start date Start date
  • Views Views 1,687
  • Replies Replies 4

DavidRO99

Average Ryzen user.
Member
Joined
Jun 11, 2016
Messages
1,018
Reaction score
301
Trophies
0
Age
28
Location
your back-door
XP
968
Country
Korea, North
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;
    }
 
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;
    }

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..
    }
}
 
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..
    }
}
Im trying to copy the file that the user selected to the Resources of the application :) You are doing the exact opposite
 
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?
 
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?
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
 

Site & Scene News

Popular threads in this forum