2024-03-06 13:00:16 -05:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
2024-03-06 18:51:23 -05:00
|
|
|
// make sure fortune directory exists
|
2024-03-06 13:00:16 -05:00
|
|
|
var resourcePath = "/usr/share/fortune-cs/";
|
|
|
|
if(!Directory.Exists(resourcePath)) {
|
|
|
|
Console.WriteLine("fortune-cs: directory '/usr/share/fortune-cs/' does not exist");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-03-06 18:51:23 -05:00
|
|
|
// pull file list
|
2024-03-06 13:00:16 -05:00
|
|
|
var files = Directory.GetFiles(resourcePath, "*.txt");
|
|
|
|
|
|
|
|
var prng = RandomNumberGenerator.Create();
|
|
|
|
|
2024-03-06 18:51:23 -05:00
|
|
|
// choose a file and line
|
2024-03-06 13:00:16 -05:00
|
|
|
var file = files[RandomNumberGenerator.GetInt32(files.Length)];
|
|
|
|
var lines = File.ReadAllLines(file);
|
|
|
|
var line = lines[RandomNumberGenerator.GetInt32(lines.Length)];
|
|
|
|
|
|
|
|
prng.Dispose();
|
|
|
|
|
2024-03-06 18:51:23 -05:00
|
|
|
// process escape codes
|
|
|
|
line = line.Replace("\\n", "\n");
|
|
|
|
|
|
|
|
// write
|
2024-03-06 13:00:16 -05:00
|
|
|
Console.WriteLine(line);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|