本文整理汇总了C#中Config.Write方法的典型用法代码示例。如果您正苦于以下问题:C# Config.Write方法的具体用法?C# Config.Write怎么用?C# Config.Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Config
的用法示例。
在下文中一共展示了Config.Write方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public override void Initialize()
{
string path = Path.Combine(TShock.SavePath, "CodeReward1_9.json");
Config = Config.Read(path);
if (!File.Exists(path))
{
Config.Write(path);
}
Commands.ChatCommands.Add(new Command(Permissions.codereward, Cmds.functionCmd, "codereward"));
Commands.ChatCommands.Add(new Command(Permissions.codereward, Cmds.functionCmd, "crt"));
Variables.ALL = Config.ALL;
//Events
ServerApi.Hooks.ServerChat.Register(this, Chat.onChat);
string version = "1.3.0.8 (1.9)";
System.Net.WebClient wc = new System.Net.WebClient();
string webData = wc.DownloadString("http://textuploader.com/al9u6/raw");
if (version != webData)
{
Console.WriteLine("[CodeReward] New version is available!: " + webData);
}
System.Timers.Timer timer = new System.Timers.Timer(Variables.ALL.Interval * (60 * 1000));
timer.Elapsed += run;
timer.Start();
}
示例2: Initialize
public override void Initialize()
{
string path = Path.Combine(TShock.SavePath, "cClassData1_4.json");
Config = Config.Read(path);
if (!File.Exists(path))
{
Config.Write(path);
}
//Events
ServerApi.Hooks.NpcStrike.Register(this, Events.OnDamage.run);
ServerApi.Hooks.ServerJoin.Register(this, Events.OnJoin.run);
ServerApi.Hooks.WorldSave.Register(this, onSave);
//Commands
Commands.ChatCommands.Add(new Command("cclass.level", Cmds.levelCmd, "level") { AllowServer = false, HelpText = "Check level" });
Commands.ChatCommands.Add(new Command("cclass.warrior", Cmds.warriorCmd, "warrior") { AllowServer = false, HelpText = "Change your class to Warrior" });
Commands.ChatCommands.Add(new Command("cclass.paladin", Cmds.paladinCmd, "paladin") { AllowServer = false, HelpText = "Change your class to Paladin" });
Commands.ChatCommands.Add(new Command("cclass.wizard", Cmds.wizardCmd, "wizard") { AllowServer = false, HelpText = "Change your class to Wizard" });
Commands.ChatCommands.Add(new Command("cclass.bwizard", Cmds.bestWizardsCmd, "bwizard") { AllowServer = false, HelpText = "Show 5 best players in Wizard class" });
Commands.ChatCommands.Add(new Command("cclass.bpaladin", Cmds.bestPaladinsCmd, "bpaladin") { AllowServer = false, HelpText = "Show 5 best players in Paladin class" });
Commands.ChatCommands.Add(new Command("cclass.bwarrior", Cmds.bestWarriorsCmd, "bwarrior") { AllowServer = false, HelpText = "Show 5 best players in Warrior class" });
Commands.ChatCommands.Add(new Command("cclass.statsadd", Cmds.statCmd, "statsadd") { AllowServer = false, HelpText = "Statictics class" });
//Load Levels etc
Variables.playersData = Config.playersData;
Variables.levelUp = Config.levelUp;
Variables.levelCommand = Config.levelCommand;
Variables.blockedNPCs = Config.blockedNPCs;
Variables.Chance = Config.Chance;
Variables.startClass = Config.startClass;
Variables.Message1 = Config.Message1;
Variables.Message2 = Config.Message2;
Variables.Message3 = Config.Message3;
}
示例3: DialogSetting
public DialogSetting()
{
Configs = new Config("Config gh-Helpful Tool v2.0 By Help-Kung", Environment.GetEnvironmentVariable("TEMP")+"\\gh2.0_HelpfulToolSettings.ini");
if (!Configs.Created)
{
Configs.Save("Folder", new String[] { "C:\\" });
Configs.Save("Speed", new String[] { "200" });
Configs.Save("Language", new String[] { "1" });
Configs.Write();
}
InitializeComponent();
ChangeLanguage();
}
示例4: Read
public void Read(Config cfg)
{
if (!File.Exists(Filename))
{
File.Create(Filename).Close();
return;
}
try
{
using (var stream = new StreamReader(Filename))
{
while (!stream.EndOfStream)
{
var line = stream.ReadLine();
line = line.Trim();
if (string.IsNullOrWhiteSpace(line))
continue;
if(!line.Contains("="))
{
var secstr = line.Substring(line.IndexOf('[') + 1, line.LastIndexOf(']') - 1);
cfg.AddSection(secstr);
cfg.SetSection(secstr);
}
else
{
var args = line.Split(new [] { '=' } , 2).Select(s => s.Trim());
cfg.Write(args.First(), args.Count() == 2 ? args.LastOrDefault() : "");
}
}
}
}
catch (Exception)
{
throw;
}
}
示例5: functionCmd
public static void functionCmd(CommandArgs e)
{
if (e.Parameters.Count > 0)
{
if (e.Parameters[0] == "help" || e.Parameters[0] == "reload" || e.Parameters[0] == "start")
{
if (e.Parameters[0] == "help")
{
e.Player.SendMessage("*--====== Commands ======--*", Color.Silver);
e.Player.SendMessage("/crt help - Show list of commands.", Color.Silver);
e.Player.SendMessage("/crt start <int> - generating new code.", Color.Silver);
e.Player.SendMessage("/crt reload - reloading plugin.", Color.Silver);
return;
}
if (e.Parameters[0] == "start")
{
if (e.Player.Group.HasPermission(Permissions.coderewardstart))
{
int length = Variables.ALL.lengthCode;
int cos = Variables.ALL.lengthCode;
bool isNumerical = false;
if (e.Parameters.Count > 1)
{
isNumerical = int.TryParse(e.Parameters[1], out cos);
}
if (isNumerical == true)
{
length = cos;
}
if (Variables.codeon2 == false)
{
codeGenerate.run(length, true);
return;
}
else
{
e.Player.SendMessage("[CodeReward] Code is already generated.", Color.Silver);
return;
}
}
else
{
e.Player.SendMessage("[CodeReward] You don't have permission.", Color.Silver);
return;
}
}
if (e.Parameters[0] == "reload")
{
if (e.Player.Group.HasPermission(Permissions.coderewardreload))
{
string path = Path.Combine(TShock.SavePath, "CodeReward1_9.json");
Config = Config.Read(path);
if (!File.Exists(path))
{
Config.Write(path);
}
Variables.ALL = Config.ALL;
e.Player.SendMessage("[CodeReward] Successfully reloaded.", Color.Silver);
return;
}
else
{
e.Player.SendMessage("[CodeReward] You don't have permission.", Color.Silver);
return;
}
}
}
else
{
e.Player.SendMessage("[CodeReward] Use /crt help", Color.Silver);
return;
}
}
else
{
e.Player.SendMessage("[CodeReward] Author: Teddy, use /crt help", Color.Silver);
return;
}
}
示例6: Setup
public static void Setup()
{
save = Path.Combine(TShock.SavePath, @"TicketSystem\Tickets.json");
banned = Path.Combine(TShock.SavePath, @"TicketSystem\Banned.txt");
TicketReader Reader = new TicketReader();
Config = new Config();
if (File.Exists(save))
{
try
{
ticketlist = Reader.readFile(save);
Console.ForegroundColor = ConsoleColor.Yellow;
if (ticketlist.Tickets.Count != 0)
Console.WriteLine(ticketlist.Tickets.Count + " tickets have been loaded.");
else
Console.WriteLine("There are no tickets.");
Console.ResetColor();
try
{
if (File.Exists(ConfigPath))
Config = Config.Read(ConfigPath);
Config.Write(ConfigPath);
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error in TicketSystem Config.json file! Check log for more details.");
Console.WriteLine(e.Message);
Console.ForegroundColor = ConsoleColor.Gray;
Log.Error("Config Exception");
Log.Error(e.ToString());
}
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error in Tickets.json file! Check log for more details.");
Console.WriteLine(e.Message);
Console.ResetColor();
Log.Error("------------- Config Exception in Ticket List file (Tickets.json) -------------");
Log.Error(e.Message);
Log.Error("---------------------------------- Error End ----------------------------------");
Console.ForegroundColor = ConsoleColor.Red;
}
}
else
{
Directory.CreateDirectory(Path.Combine(TShock.SavePath, "TicketSystem"));
ticketlist = Reader.writeFile(save);
using (StreamWriter writer = new StreamWriter(tagpath, true))
{
writer.WriteLine("Default");
writer.WriteLine("Grief");
writer.WriteLine("Report");
writer.WriteLine("High-Importance");
}
using (StreamWriter writer = new StreamWriter(Path.Combine(TShock.SavePath, @"TicketSystem\loginmsg.txt"), true))
{
writer.WriteLine("To write a complaint, use \"/ticket [-t:<tag>] <Message>\"");
writer.WriteLine("NOTE: Tags are optional. To view a list of tags, use \"/ticket tags\"");
}
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("There are no tickets.");
Console.ResetColor();
Log.Info("No tickets submitted.");
}
}
示例7: DoWorkInitialize
public void DoWorkInitialize(object sender, DoWorkEventArgs e)
{
switch (Processing)
{
case Algorithm.Initialize:
Settings = new DialogSetting();
ThreadWorker.ReportProgress(-1);
if (!Directory.Exists(TempFiles)) Directory.CreateDirectory(TempFiles);
break;
case Algorithm.Verfify:
Int32 iReq = 0;
do {
UpdateTexting = "[" + (iReq + 1) + "/" + RequestURL.Count + "] " + Settings.Configs.GetValue("NOW_VERUFY");
ThreadWorker.ReportProgress(-2);
Thread.Sleep(1000);
SyncNet dnsVerify = new SyncNet(RequestURL[iReq].ToString());
if (dnsVerify.Connected)
{
Int32 ContentLenght = 0;
Int32 NowLenght = 0;
Dictionary<String, String> Response = dnsVerify.ResponseHeader("");
if (Response.ContainsKey("Content-Length")) ContentLenght = Int32.Parse(Response["Content-Length"]);
String ResponseHTML = "";
if (Response["HTTP"] == "200 OK")
{
// Speed Checking kb/s Timer.
ThreadWorker.ReportProgress(-3);
do
{
ResponseHTML += dnsVerify.Response(Int32.Parse(Settings.Configs.GetValue("Speed")) * 1024);
NowLenght += dnsVerify.Downloading;
UpdateTexting = "[" + (iReq + 1) + "/" + RequestURL.Count + "] " + Settings.Configs.GetValue("NOW_CONNECTING");
ThreadWorker.ReportProgress((Int32)((NowLenght * 100) / ContentLenght));
ResponseLenght += dnsVerify.Downloading;
} while (NowLenght < ContentLenght);
ThreadWorker.ReportProgress(-4);
if (ResponseHTML.Trim() != "Key missing, or incorrect key provided.")
{
String NameManga = SplitUp.GetCenter(ResponseHTML, "<h1 id=\"gn\">", "</h1>").Trim();
String PagesManga = SplitUp.GetCenter(ResponseHTML, "Images:</td><td class=\"gdt2\">", "</td>").Trim();
String SizesManga = SplitUp.GetRight(PagesManga, " @ ").Trim();
if (NameManga != "" && PagesManga != "" && SizesManga != "")
{
PagesManga = SplitUp.GetLeft(PagesManga, " @ ").Trim();
// Thai Encoding
Byte[] byteName = Encoding.UTF8.GetBytes(NameManga);
NameManga = Encoding.UTF8.GetString(byteName, 0, byteName.Length);
String RatingManga = "";
for (Int16 iRating = 0; iRating < (Int32)Math.Round(Double.Parse(SplitUp.GetCenter(ResponseHTML, "original_rating = ", ";").Trim()), 0); iRating++) RatingManga += "* ";
String gidToken = SplitUp.GetCenter(ResponseHTML, "gid = ", ";").Trim() + "_" + SplitUp.GetCenter(ResponseHTML, "token = \"", "\";").Trim();
ListImages = new List<String>();
Int32 PageLoop = 0;
do
{
PageLoop++;
ResponseHTML = SplitUp.GetRight(ResponseHTML, "<p class=\"ip\">Showing");
ResponseHTML = SplitUp.GetLeft(ResponseHTML, "<table class=\"ptb\" style=\"margin:0px auto 10px\">");
foreach (String list in Regex.Split(ResponseHTML, "<a href=\"http://"))
{
String ImageUrl = SplitUp.GetLeft(list, "\"><img alt=");
if (Regex.IsMatch(ImageUrl, dnsVerify.DomainName) && !Regex.IsMatch(ImageUrl, "Images"))
{
ListImages.Add(ImageUrl.Trim());
Console.WriteLine(ImageUrl.Trim());
}
}
if (ListImages.Count < Int32.Parse(PagesManga))
{
ContentLenght = 0;
NowLenght = 0;
UpdateTexting = "[" + (iReq + 1) + "/" + RequestURL.Count + "] " + Settings.Configs.GetValue("NOW_CONNECTING")
+ " " + (PageLoop + 1) + "/" + Math.Ceiling(float.Parse(PagesManga) / 20).ToString() + " " + Settings.Configs.GetValue("NOW_PAGE");
ThreadWorker.ReportProgress(0);
Thread.Sleep(500);
dnsVerify = new SyncNet(RequestURL[iReq].ToString());
if (dnsVerify.Connected)
{
Response = dnsVerify.ResponseHeader("?p=" + PageLoop);
if (Response.ContainsKey("Content-Length")) ContentLenght = Int32.Parse(Response["Content-Length"]);
ResponseHTML = "";
ThreadWorker.ReportProgress(-3);
do
{
ResponseHTML += dnsVerify.Response(Int32.Parse(Settings.Configs.GetValue("Speed")) * 1024);
NowLenght += dnsVerify.Downloading;
UpdateTexting = "[" + (iReq + 1) + "/" + RequestURL.Count + "] " + Settings.Configs.GetValue("NOW_CONNECTING")
+ " " + (PageLoop + 1) + "/" + Math.Ceiling(float.Parse(PagesManga) / 20).ToString() + " " + Settings.Configs.GetValue("NOW_PAGE");
ThreadWorker.ReportProgress((Int32)((NowLenght * 100) / ContentLenght));
ResponseLenght += dnsVerify.Downloading;
} while (NowLenght < ContentLenght);
ThreadWorker.ReportProgress(-4);
}
}
} while (ListImages.Count < Int32.Parse(PagesManga));
//.........这里部分代码省略.........
示例8: toolbtnDelete_Click
private void toolbtnDelete_Click(object sender, EventArgs e)
{
if (ListHentai.Items[ItemIndexed].ImageIndex == -1 || ListHentai.Items[ItemIndexed].ImageIndex == 2 || ListHentai.Items[ItemIndexed].ImageIndex == 0)
{
Boolean IndexFound = false;
Int32 IndexItemsID = 0;
foreach (String filename in Directory.GetFiles(TempFiles))
{
Config DumpList = new Config("", filename);
if (IndexFound)
{
DumpList.Close();
File.Delete(filename);
String id_name = IndexItemsID.ToString();
while (id_name.Length < IDMax) id_name = "0" + id_name;
Config ReIndexed = new Config(DumpList.GetValue("Name") + " Dump Files ", TempFiles + id_name + "-" + DumpList.GetValue("Name") + ".txt");
ReIndexed.Save("URL", DumpList.GetList("URL").ToArray());
ReIndexed.Save("Key", DumpList.GetList("Key").ToArray());
ReIndexed.Save("Name", DumpList.GetList("Name").ToArray());
ReIndexed.Save("Sizes", DumpList.GetList("Sizes").ToArray());
ReIndexed.Save("Pages", DumpList.GetList("Pages").ToArray());
ReIndexed.Save("Rating", DumpList.GetList("Rating").ToArray());
ReIndexed.Save("Status", DumpList.GetList("Status").ToArray());
ReIndexed.Save("ID", DumpList.GetList("ID").ToArray());
ReIndexed.Save("Links", DumpList.GetList("Links").ToArray());
ReIndexed.Write();
ReIndexed.Close();
ListHentai.Items[IndexItemsID].SubItems[0].Text = (IndexItemsID + 1).ToString();
}
else
{
if (DumpList.GetValue("ID") == ListHentai.Items[ItemIndexed].SubItems[7].Text)
{
DumpList.Delete();
ListHentai.Items[ItemIndexed].Remove();
IndexFound = true;
IndexItemsID--;
if ((ListHentai.Items.Count - 1) < ItemIndexed) ItemIndexed--;
ListHentai.Items[ItemIndexed].Selected = true;
}
}
IndexItemsID++;
}
}
}
示例9: DoWorkDownloade
public void DoWorkDownloade(object sender, DoWorkEventArgs e)
{
ImagesCurrent = 0;
Int32 FileCurrent = 0;
String[] ListFiles = Directory.GetFiles(TempFiles);
do
{
if (DownloadWorker.CancellationPending == true)
{
e.Cancel = true;
break;
}
else
{
String FileName = ListFiles[FileCurrent];
Config Items = new Config("", FileName);
Items.Close();
String ImageFolder = Settings.Configs.GetValue("Folder") + Items.GetValue("Name") + "\\";
if (Items.GetValue("Key") != "2")
{
DownloadWorker.ReportProgress(-1);
CurrentItem = Items.GetValue("ID");
TotalImages = Items.GetList("Links").Count;
foreach (String url in Items.GetList("Links"))
{
Console.WriteLine("----------------------------------------------------------------");
if (DownloadWorker.CancellationPending == true)
{
e.Cancel = true;
break;
}
else
{
Boolean ImageFailsLoading;
String RetryImage = "";
String URLImage = "";
Int32 ImageError = 0;
do
{
ImageFailsLoading = true;
Items = new Config(Items.HeaderTitle, FileName);
Thread.Sleep(100);
if (DownloadWorker.CancellationPending == true)
{
e.Cancel = true;
break;
}
else
{
Int32 ContentLenght = 0;
Int32 NowLenght = 0;
Int32 ImageLenght = 0;
String ImageName = "";
String ResponseHTML = "";
Boolean ReceiveLink = true;
Boolean ReceiveImage = true;
Dictionary<String, String> Response;
List<String> Images = Items.GetList("Images");
Console.WriteLine("Images: " + Images.Count + " Current: " + (ImagesCurrent + 1));
if (Images.Count > ImagesCurrent)
{
String[] data = Regex.Split(Images[ImagesCurrent].Trim(), "#");
ImageName = data[0];
if (data[1] != "") ImageLenght = Int32.Parse(data[1]);
}
if (ImageLenght != 0 && File.Exists(ImageFolder + ImageName))
{ // Check Image File
Console.WriteLine("Exists Image: " + ImageName);
FileStream ImageStream = new FileStream(ImageFolder + ImageName, FileMode.Open, FileAccess.Read);
if (ImageStream.Length != ImageLenght)
{
ImageStream.Close();
File.Delete(ImageFolder + ImageName);
Console.WriteLine(" <<===== Exists: false");
}
else
{
ImagesCurrent++;
ReceiveLink = false;
ReceiveImage = false;
ImageFailsLoading = false;
Console.WriteLine(" <<===== Exists: true");
}
if (ImageStream.CanRead) ImageStream.Close();
}
if (ReceiveLink)
{ // Get Images From URL
Console.WriteLine("Geting URL...");
SyncNet DnsGetingURL = new SyncNet(url);
if (DnsGetingURL.Connected)
{
Response = DnsGetingURL.ResponseHeader(RetryImage);
// foreach (KeyValuePair<String, String> head in Response) Console.WriteLine(head.Key + ": " + head.Value);
if (Response.ContainsKey("Content-Length")) ContentLenght = Int32.Parse(Response["Content-Length"]);
if (Response["HTTP"] == "200 OK" && ContentLenght != 0)
//.........这里部分代码省略.........