Esempio n. 1
0
 private void CommandDATANEWDAY(string[] tokens)
 {
     /* @DATANEWDAY <filename> :  If it is the NEXT day since this function was
         called, all records in <filename> will be set to 0.  Check EXAMPLE.REF in the
         LORD II archive for an example of how this works.
         NOTE: You should specify an extension (usually .IDF) */
     string FileName = Global.GetSafeAbsolutePath(RTVariables.TranslateVariables(tokens[1]));
     if (FileName != "")
     {
         if (File.Exists(FileName))
         {
             using (FileStream FS = new FileStream(FileName, FileMode.Open))
             {
                 IGM_DATA IGMD = DataStructures.ReadStruct<IGM_DATA>(FS);
                 if (IGMD.LastUsed != (DateTime.Now.Month + DateTime.Now.Day))
                 {
                     IGMD.LastUsed = (DateTime.Now.Month + DateTime.Now.Day);
                     for (int i = 0; i < IGMD.Data.Length; i++)
                     {
                         IGMD.Data[i] = 0;
                     }
                     for (int i = 0; i < IGMD.Extra.Length; i++)
                     {
                         IGMD.Extra[i] = '\0';
                     }
                     DataStructures.WriteStruct<IGM_DATA>(FS, IGMD);
                 }
             }
         }
         else
         {
             using (FileStream FS = new FileStream(FileName, FileMode.Create, FileAccess.Write))
             {
                 IGM_DATA IGMD = new IGM_DATA(true);
                 IGMD.LastUsed = DateTime.Now.Month + DateTime.Now.Day;
                 for (int i = 0; i < IGMD.Data.Length; i++)
                 {
                     IGMD.Data[i] = 0;
                 }
                 for (int i = 0; i < IGMD.Extra.Length; i++)
                 {
                     IGMD.Extra[i] = '\0';
                 }
                 DataStructures.WriteStruct<IGM_DATA>(FS, IGMD);
             }
         }
     }
 }
Esempio n. 2
0
        private void CommandDATASAVE(string[] tokens)
        {
            /* @DATASAVE <filename> <record (1 to 200)> <value to make it> : This SAVES
                a long integer by # to a datafile.  If the file doesn't exist, it is created
                and all 200 long integers (except the one referenced) are set to 0.  The
                record that is referenced will be set to the value of the 3rd parameter.
                NOTE: You should specify an extension (usually .IDF) */
            string FileName = Global.GetSafeAbsolutePath(RTVariables.TranslateVariables(tokens[1]));
            if (FileName != "")
            {
                if (File.Exists(FileName))
                {
                    using (FileStream FS = new FileStream(FileName, FileMode.Open, FileAccess.ReadWrite))
                    {
                        // Read file
                        IGM_DATA IGMD = DataStructures.ReadStruct<IGM_DATA>(FS);
                        IGMD.Data[Convert.ToInt32(RTVariables.TranslateVariables(tokens[2])) - 1] = Convert.ToInt32(RTVariables.TranslateVariables(tokens[3]));

                        // Write file
                        FS.Position = 0;
                        DataStructures.WriteStruct<IGM_DATA>(FS, IGMD);
                    }
                }
                else
                {
                    using (FileStream FS = new FileStream(FileName, FileMode.Create, FileAccess.Write))
                    {
                        IGM_DATA IGMD = new IGM_DATA(true);
                        IGMD.LastUsed = DateTime.Now.Month + DateTime.Now.Day;
                        for (int i = 0; i < IGMD.Data.Length; i++)
                        {
                            IGMD.Data[i] = 0;
                        }
                        IGMD.Data[Convert.ToInt32(RTVariables.TranslateVariables(tokens[2])) - 1] = Convert.ToInt32(RTVariables.TranslateVariables(tokens[3]));
                        for (int i = 0; i < IGMD.Extra.Length; i++)
                        {
                            IGMD.Extra[i] = '\0';
                        }
                        DataStructures.WriteStruct<IGM_DATA>(FS, IGMD);
                    }
                }
            }
        }
Esempio n. 3
0
 private void CommandDATALOAD(string[] tokens)
 {
     /* @DATALOAD <filename> <record (1 to 200)> <`p variable to put it in> : This loads
         a long integer by # from a datafile.  If the file doesn't exist, it is created
         and all 200 long integers are set to 0.
         NOTE: You should specify an extension (usually .IDF) */
     string FileName = Global.GetSafeAbsolutePath(RTVariables.TranslateVariables(tokens[1]));
     if (FileName != "")
     {
         if (File.Exists(FileName))
         {
             using (FileStream FS = new FileStream(FileName, FileMode.Open))
             {
                 IGM_DATA IGMD = DataStructures.ReadStruct<IGM_DATA>(FS);
                 RTVariables.SetVariable(tokens[3], IGMD.Data[Convert.ToInt32(RTVariables.TranslateVariables(tokens[2])) - 1].ToString());
             }
         }
         else
         {
             using (FileStream FS = new FileStream(FileName, FileMode.Create, FileAccess.Write))
             {
                 IGM_DATA IGMD = new IGM_DATA(true);
                 IGMD.LastUsed = DateTime.Now.Month + DateTime.Now.Day;
                 for (int i = 0; i < IGMD.Data.Length; i++)
                 {
                     IGMD.Data[i] = 0;
                 }
                 for (int i = 0; i < IGMD.Extra.Length; i++)
                 {
                     IGMD.Extra[i] = '\0';
                 }
                 DataStructures.WriteStruct<IGM_DATA>(FS, IGMD);
             }
             RTVariables.SetVariable(tokens[3], "0");
         }
     }
 }