C# INI Reader & Writer

D

Drenated

Legend Member
Joined
Nov 23, 2019
Messages
1,865
Reaction score
1,517
İlk olarak InteropServices kütüphanesini projemize ekleyelim

C#:
using System.Runtime.InteropServices;

Daha sonra class'ımızı oluşturalım

C#:
public class INIKaydet

        {

            [DllImport("kernel32")]

            private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

            [DllImport("kernel32")]

            private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);



            public INIKaydet(string dosyaYolu)

            {

                DOSYAYOLU = dosyaYolu;

            }

            private string DOSYAYOLU = String.Empty;

            public string Varsayilan { get; set; }

            public string Oku(string bolum, string ayaradi)

            {

                Varsayilan = Varsayilan ?? string.Empty;

                StringBuilder StrBuild = new StringBuilder(256);

                GetPrivateProfileString(bolum, ayaradi, Varsayilan, StrBuild, 255, DOSYAYOLU);

                return StrBuild.ToString();

            }

            public long Yaz(string bolum, string ayaradi, string deger)

            {

                return WritePrivateProfileString(bolum, ayaradi, deger, DOSYAYOLU);

            }

        }

Source'si hazır şimdi ise kullanıma geçelim

C#:
   INIKaydet ınıreadwrite = new INIKaydet(Application.StartupPath + @"/proto.cfg"); // istediğiniz uzantıda yapabilirsiniz ben cfg'yi tercih ettim

   string read = ınıreadwrite.Oku("Glow Esp", "Sleep"); //(Okuma)fyreina.cfg'deki Glow Esp başlığı adı altındaki Sleep'in değerini read stringine   aktar

   ınıreadwrite.Yaz("Glow Esp", "Sleep", textBox1.Text); //(Yazma)proto.cfg'deki Glow Esp başlığı adı altındaki Sleep'in değerine textbox1'deki değeri yazdır
 
SPAM IS FORBIDDEN!
  • SPAMMERS ARE BANNED FROM THE FORUM AND CANNOT USE ANY OF THE CHEATS
  • For example: thanks, thx, very good, asdqwe, working, ty and so on!
  • For example: Writing the same message over and over. thanks, thx and so on!
  • Copying and copying someone else's message is prohibited.
  • It is forbidden to send messages to increase the number of comments on threads that you have no knowledge of.
  • Write your own opinion when commenting!
  • If you see spam message, please let us know with the REPORT button!

Tema düzenleyici

Top Bottom