• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SetDsplFile()
#1
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
  Reply
#2
@Ich1994 Tried to help me with it last night but it didnt work ingame. can somebody help?
  Reply
#3
Why to you need a function for that? Can't you use the standard C# functions to open and write to a file?
[Image: azuw.jpg]
[-] The following 1 user says Thank You to zxz0O0 for this post:
  • OzonE
  Reply
#4
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;

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

[Image: azuw.jpg]
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)