using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace IReaper.Initializer{
//
public class CheckUniqueUserIDTask:AbstractInitTask
{
protected override void JobContent()
{
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "iReaper");
if (!Directory.Exists(path))
{
try
{
Directory.CreateDirectory(path);
}
catch
{
return;
}
}
Properties.Settings.Default.UserID = GenerateUserID(path);
}
private Guid GenerateUserID(string Dir)
{
string path = Path.Combine(Dir, ".user");
try
{
//Guid
if (!File.Exists(path))
{
Guid userID = Guid.NewGuid();
File.WriteAllBytes(path, userID.ToByteArray());
return userID;
}
else
{
byte[] buffer = File.ReadAllBytes(path);
Guid userID = new Guid(buffer);
return userID;
}
}
catch
{
return Guid.Empty;
}
}
}
}
|