ClientLauncher.IniFiles.GetSectionValuesAsList C# (CSharp) Метод

GetSectionValuesAsList() публичный Метод

Gets all of the values in a section as a list.
/// is a null reference (Nothing in VB) ///
public GetSectionValuesAsList ( string sectionName ) : string>>.List
sectionName string /// Name of the section to retrieve values from. ///
Результат string>>.List
        public List<KeyValuePair<string, string>> GetSectionValuesAsList(string sectionName)
        {
            List<KeyValuePair<string, string>> retval;
            string[] keyValuePairs;
            string key, value;
            int equalSignPos;

            if (sectionName == null)
                throw new ArgumentNullException("sectionName");

            //Allocate a buffer for the returned section names.
            IntPtr ptr = Marshal.AllocCoTaskMem(IniFiles.MaxSectionSize);

            try
            {
                //Get the section key/value pairs into the buffer.
                int len = NativeMethods.GetPrivateProfileSection(sectionName,
                                                                 ptr,
                                                                 IniFiles.MaxSectionSize,
                                                                 m_path);

                keyValuePairs = ConvertNullSeperatedStringToStringArray(ptr, len);
            }
            finally
            {
                //Free the buffer
                Marshal.FreeCoTaskMem(ptr);
            }

            //Parse keyValue pairs and add them to the list.
            retval = new List<KeyValuePair<string, string>>(keyValuePairs.Length);

            for (int i = 0; i < keyValuePairs.Length; ++i)
            {
                //Parse the "key=value" string into its constituent parts
                equalSignPos = keyValuePairs[i].IndexOf('=');

                key = keyValuePairs[i].Substring(0, equalSignPos);

                value = keyValuePairs[i].Substring(equalSignPos + 1,
                                                   keyValuePairs[i].Length - equalSignPos - 1);

                retval.Add(new KeyValuePair<string, string>(key, value));
            }

            return retval;
        }

Usage Example

Пример #1
0
        private void FinishedGettingTRE(IAsyncResult theResult)
        {
            CustomeTreCallObject          theObject     = theResult.AsyncState as CustomeTreCallObject;
            List <LauncherData.CustomTre> lstCustomTres = theObject.TheClient.EndGetCustomTre(theResult);

            if (PatchStepFired != null)
            {
                PatchStepFired(this, new PatchingEventArgs(myVariables.Found + " " + lstCustomTres.Count.ToString(), false));
                PatchStepFired(this, new PatchingEventArgs(myVariables.CustomServerDir, true));
            }


            //does our directory even exist?
            if (!Directory.Exists(SWGANHPAth + theObject.Server.SafeFolderName))
            {
                if (PatchStepFired != null)
                {
                    PatchStepFired(this, new PatchingEventArgs(myVariables.NotFound, false));
                }
                CopyRequiredFiles(theObject.Server);
            }
            else
            {
                if (PatchStepFired != null)
                {
                    PatchStepFired(this, new PatchingEventArgs(myVariables.Found, false));
                }
            }

            if (PatchStepFired != null)
            {
                PatchStepFired(this, new PatchingEventArgs(myVariables.ValidatingFiles, true));
            }
            //now to check the files are correctly patched

            IniFiles myFiles = new IniFiles(SWGANHPAth + "\\swg2uu_live.cfg");
            List <KeyValuePair <string, string> > lstStandardFiles = myFiles.GetSectionValuesAsList("SharedFile");


            if (PatchStepFired != null)
            {
                PatchStepFired(this, new PatchingEventArgs(myVariables.Found + " " + lstStandardFiles.Count.ToString(), false));
            }

            bool blnSuccess = true;

            foreach (KeyValuePair <string, string> thePair in lstStandardFiles)
            {
                //prepare the filename
                string strFileName = thePair.Value.Substring(1, thePair.Value.Length - 2);

                //is it a file?
                if (File.Exists(strFileName))
                {
                    using (FileStream fileIn = new FileStream(strFileName, FileMode.Open, FileAccess.Read))
                    {
                        byte[] arMD5Bytes = hashmd5.ComputeHash(fileIn);

                        //find the file in the Standard List
                        StandardTre theCurrentFile = myUserPreferences.CachedStandardTre.Find(st => st.Filename.Equals(Path.GetFileName(strFileName), StringComparison.InvariantCultureIgnoreCase));

                        if (theCurrentFile != null)
                        {
                            if (PatchStepFired != null)
                            {
                                PatchStepFired(this, new PatchingEventArgs(myVariables.Validating + " " + Path.GetFileName(strFileName), true));

                                if (BitConverter.ToString(arMD5Bytes).Replace("-", "") == theCurrentFile.MD5Hash)
                                {
                                    PatchStepFired(this, new PatchingEventArgs(myVariables.Passed, false));
                                }
                                else
                                {
                                    PatchStepFired(this, new PatchingEventArgs(myVariables.Failed, false));

                                    //something failed
                                    blnSuccess = false;
                                }
                            }
                        }
                    }
                }
            }

            if (PatchFunctionComplete != null)
            {
                string strPatchCompleteMessage = myVariables.ClientUpToDate;
                if (!blnSuccess)
                {
                    strPatchCompleteMessage = myVariables.ClientOutOfDate + Environment.NewLine + myVariables.PatchFromSWG;
                }
                PatchFunctionComplete(this, new PatchFunctionCompleteEventArgs(strPatchCompleteMessage, blnSuccess));
            }
        }
All Usage Examples Of ClientLauncher.IniFiles::GetSectionValuesAsList