ItsMods

Full Version: SetDsplFile()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
can it be a method like GetServerCFG and SetServerCFG that Writes a String In The First Line Of a Dspl File, and another Method Like DeleteDsplFile() that Erases Whatever it is in the first line of the dspl file?

@zxz0O0
@Ich1994 Tried to help me with it last night but it didnt work ingame. can somebody help?
Why to you need a function for that? Can't you use the standard C# functions to open and write to a file?
yes , @Ich1994 wrote me a code to do that , but it does not work.
here

Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Addon;

namespace ServerAdmin
{
    public  class GameChanger : CPlugin
    {
        public static bool WriteFirstLineToFile(String Text, String PathToFile)
        {
            if (!File.Exists(PathToFile))
                return false;//File do not Exist

            FileStream fs = File.OpenWrite(PathToFile);

            if (!fs.CanWrite)
                return false;//Can not be written

            string tempfile = Path.GetTempFileName();
            StreamWriter writer = new StreamWriter(tempfile);
            StreamReader reader = new StreamReader(PathToFile);

            writer.WriteLine(Text);
            while (!reader.EndOfStream)
                writer.WriteLine(reader.ReadLine());
            writer.Close();
            reader.Close();
            File.Copy(tempfile, PathToFile, true);


            return true;
        }

        public static bool DeleteFirstLineToFile(String PathToFile)
        {
            if (!File.Exists(PathToFile))
                return false;//File do not Exist

            FileStream fs = File.OpenWrite(PathToFile);

            if (!fs.CanWrite)
                return false;//Can not be written

            string tempfile = Path.GetTempFileName();
            StreamWriter writer = new StreamWriter(tempfile);
            StreamReader reader = new StreamReader(PathToFile);

            reader.ReadLine();
            while (!reader.EndOfStream)
                writer.WriteLine(reader.ReadLine());
            writer.Close();
            reader.Close();
            File.Copy(tempfile, PathToFile, true);


            return true;

        }
    }
}
Uhm, well then maybe check why it doesn't work?