Saito Hiraga

Saito Hiraga

  • NA
  • 11
  • 680

c# constructor issues

Jan 2 2016 7:44 PM
Ok hello sharpcorner 
 
i been having a issue now for ages and cant seem to find out why its causing me issues  but here is a lines of the code 
 
Ok main form1
  1. elfenlied_program_settings elf;  
  2. addingweapons elf_weap;  
  3. Parser elfenliedl;  
  4. gscadding elfy1;  
  5.   
  6.   
  7. //Parser parser = new Parser("model1887_sp");  
  8.   
  9.   
  10.   
  11. public Form1()  
  12. {  
  13.   
  14.     InitializeComponent();  
  15.   
  16.     updater1.CheckForUpdates();  
  17.     listBoxAdv1.Visible = false;  
  18.     elf = new elfenlied_program_settings(listBoxAdv1,elfenliedl);  
  19.     elf_weap = new addingweapons(richTextBoxEx1);  
  20.     elfenliedl = new Parser("model1887_sp");  
  21.     elfy1 = new gscadding(this, elf_weap);  
  22.     elfy1.elfygsc = this 
  23.     timer1.Start();  
  24.     elf.buttonX2 = buttonX2;  
  25.     elf.elfenform = this;  
  26.    // elfe.elfgsc = this;  
  27.     buttonX2.Visible = false;  
  28.     buttonX3.Enabled = true;  
  29.     textBoxX6.Enabled = false;  
  30.     elfenliedl.buttonX1 = buttonX1;  
  31.   
  32.     // last thing to add hopfully   
  33.   
  34.     if (Properties.Settings.Default.root.Equals("First"))  
  35.     {  
  36.         if (Directory.Exists(wawpath))  
  37.         {  
  38.             Properties.Settings.Default.root.Equals(wawpath);  
  39.             string rootsave = wawpath;  
  40.             Properties.Settings.Default.root = rootsave;  
  41.             Properties.Settings.Default.Save();  
  42.             listBoxAdv1.Visible = true;  
  43.             root = Properties.Settings.Default.root;  
  44.             buttonX2.Visible = true;  
  45.             elf.newlistbox();  
  46.             elf.listboxfunction();  
  47.             updatesettings();  
  48.               
  49.         }  
  50.     }  
  51.     else  
  52.     {  
  53.         MessageBox.Show("we did not hit it");  
  54.     }  
  55.   
  56.        
  57. }  
         
the methord i want to reach in form1  
 
  1. public void updatesettings()  
  2. {  
  3.     mods = Properties.Settings.Default.mods + "//maps//_zombiemode_weapons.gsc";  
  4.     dlc3code = Properties.Settings.Default.mods + "//maps//dlc3_code.gsc";  
  5.     zombiemodeweapons = Properties.Settings.Default.mods + "//maps//_zombiemode_weapons.gsc";  
  6. }  
 
and what im trying to do is get gscadder to revrence  form 1 to update string paths as follows here 
 
gscadding
 and i want here to revrence updatesettings in form1
 
  1. public SoundAlis sounds;  
  2. public addingweapons dlc3gsc;  
  3. public Form1 elfygsc;  
  4. public gscadding(addingweapons dlc3)  
  5. {  
  6.     dlc3gsc = dlc3;  
  7. }  
  8.   
  9. public gscadding(Form1 elfygsc,addingweapons dlc3)  
  10. {  
  11.     this.elfygsc = elfygsc;  
  12. }  
  13. /// <summary>  
  14. /// MODEL 1887 DLC3....  
  15. /// </summary>  
  16. public void dlcexists()  
  17. {  
  18.   
  19.     elfygsc.updatesettings();  
  20.     if (dlc3gsc.Model1887 == true)  
  21.     {   
  22.         if (File.Exists(dlc3code))  
  23.         {  
  24.             MessageBox.Show("exists");  
  25.         }  
  26.         else  
  27.         {  
  28.             DialogResult dialogResult = MessageBox.Show("Dlc3code.gsc is not found in mods do you wish to copy.""Dlc3_code.gsc not found in mods", MessageBoxButtons.YesNo);  
  29.             if (dialogResult == DialogResult.Yes)  
  30.             {  
  31.                 File.Copy(Properties.Settings.Default.root + "\\raw\\maps\\dlc3_code.gsc", Properties.Settings.Default.mods + "//maps//dlc3_code.gsc"true);  
  32.                 {  
  33.                     string s = "include_weapon( \"model1887_sp\");"//string s = "include_weapon( \"hk416_zm\");";  
  34.   
  35.                     string file = modspath1 + "//maps//dlc3_code.gsc";  
  36.                     List<string> lines = new List<string>(System.IO.File.ReadAllLines(file));  
  37.                     int index = lines.FindLastIndex(item => item.Contains(("include_weapon(")));  
  38.                     if (index != -1)  
  39.                     {  
  40.                         lines.Insert(index + 1, s);//""  
  41.                     }  
  42.                     System.IO.File.WriteAllLines(file, lines);  
  43.                     MessageBox.Show("done");  
  44.                 }  
  45.             }  
  46.   
  47.             else if (dialogResult == DialogResult.No)  
  48.             {  
  49.                 MessageBox.Show("No Files Copied To Add files to the mystery box you will need to add lines later");  
  50.             }  
  51.         }  
  52.     }  
 and i do have a call in another class im not sure if this is what is causing it or not but i dont think so as that one revrences the form1 as well 
 
addingweapons.cs
 
  1. SoundAlis sounds;  
  2. gscadding elfgscadd;  
  3. public bool M27 { getset; }  
  4. public bool Model1887 { getset; }  
  5.   
  6.   
  7.   
  8.   
  9. // copying files   
  10. private void DirectoryCopy(  
  11. string sourceDirName, string destDirName, bool copySubDirs)  
  12. {  
  13.     DirectoryInfo dir = new DirectoryInfo(sourceDirName);  
  14.     DirectoryInfo[] dirs = dir.GetDirectories();  
  15.   
  16.     // If the source directory does not exist, throw an exception.  
  17.     if (!dir.Exists)  
  18.     {  
  19.         throw new DirectoryNotFoundException(  
  20.             "Source directory does not exist or could not be found: "  
  21.             + sourceDirName);  
  22.     }  
  23.   
  24.     // If the destination directory does not exist, create it.  
  25.     if (!Directory.Exists(destDirName))  
  26.     {  
  27.         Directory.CreateDirectory(destDirName);  
  28.     }  
  29.   
  30.   
  31.     // Get the file contents of the directory to copy.  
  32.     FileInfo[] files = dir.GetFiles();  
  33.   
  34.     foreach (FileInfo file in files)  
  35.     {  
  36.         // Create the path to the new copy of the file.  
  37.         string temppath = Path.Combine(destDirName, file.Name);  
  38.   
  39.         // Copy the file.  
  40.         file.CopyTo(temppath, true);  
  41.     }  
  42.   
  43.     // If copySubDirs is true, copy the subdirectories.  
  44.     if (copySubDirs)  
  45.     {  
  46.   
  47.         foreach (DirectoryInfo subdir in dirs)  
  48.         {  
  49.             // Create the subdirectory.  
  50.             string temppath = Path.Combine(destDirName, subdir.Name);  
  51.   
  52.             // Copy the subdirectories.  
  53.             DirectoryCopy(subdir.FullName, temppath, copySubDirs);  
  54.         }  
  55.     }  
  56. }  
  57.   
  58. public addingweapons(DevComponents.DotNetBar.Controls.RichTextBoxEx richtextboxelf)  
  59. {  
  60.       
  61.     richTextBoxEx1 = richtextboxelf;  
  62.    // opnwep = new Parser(this);  
  63.     elfgscadd = new gscadding(this);  
  64.     sounds = new SoundAlis(this, elfgscadd);  
  65.     elfgscadd.sounds = sounds;  
  66.       
  67.   
  68.     // textboxes   
  69.       
  70.       
  71.       
  72.       
  73.   
  74.   
  75. }  
 And this is the error i get once i push copy weapons 
 
 
 
Thank you in advance Saito  

Answers (11)