I have created dll file using C# Utils.dll which content function replace_string within the class StringUtils. The function is successfully call and give result when call within the console application. Now, I have included the dll file in plugins/ansi folder within NSIS.
I have tried to call the function as :
Utils.StringUtils::replace_string "E:\\test\\test.txt" 'abcd' 'efgh'
I have also tried using CLR
CLR::Call /NOUNLOAD Utils.dll Utils.StringUtils replace_string 3 "E:\\test\\test.txt" 'abcd' 'efgh'
And again with System call
System::Call 'Utils::StringUtils.replace_string("E:\\test\\test.txt", "abcd", "efgh");'
But i got errors while compiling the nsi file. What could be the correct implementation of function in dll file at NSIS?
C# Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace Utils
{
public class StringUtils
{
public StringUtils()
{
}
///
/// Replace the data in the Huge files searching and replacing chunk
/// by chunk. It will create new file as filepath + ".tmp" file with
/// replaced data
///
/// Path of the file
/// Text to be replaced
/// Text with which it is replaced
public static void replace_string(string filePath, string replaceText, string withText)
{
StreamReader streamReader = new StreamReader(filePath);
StreamWriter streamWriter = new StreamWriter(filePath + ".tmp");
while (!streamReader.EndOfStream)
{
string data = streamReader.ReadLine();
data = data.Replace(replaceText, withText);
data = Regex.Replace(data, replaceText, withText);
streamWriter.WriteLine(data);
}
streamReader.Close();
streamWriter.Close();
}
public static void print_text()
{
Console.WriteLine("test");
Console.ReadKey();
}
}
}
Console Application Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utils;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
StringUtils.replace_string("E:\\test\\test.txt", "abcd", "efgh");
//Class1.print_text();
}
}
}
Here i have called the replace_string function from the console application and it successfully executed and give the correct result where as when called within NSIS outputs error.