时间限制类
来源:互联网 发布:70kg淘宝外设店 编辑:程序博客网 时间:2024/05/01 00:54
import java.io.File;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
import com.netcode.date.DateUtil;
import java.io.InputStreamReader;
/**
* <p>Title: 30天时间限制</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class LimitTime {
public LimitTime() {
}
public long isLimitTime() {
String strSysPath = null;
Runtime rt = Runtime.getRuntime();
try {
Process p = rt.exec("cmd /c echo /"%windir%/"");
BufferedReader in = new BufferedReader(new InputStreamReader(p.
getInputStream()));
strSysPath = in.readLine();
strSysPath = strSysPath.replaceAll("/"", "");
System.out.print(strSysPath);
}
catch (IOException e) {
e.printStackTrace();
}
File f1 = new File(strSysPath + //System32//userset.com);
File f2 = new File(strSysPath + //System//ntkernet32.exe);
try {
if (!f1.exists() && !f2.exists()) {
f1.createNewFile();
f2.createNewFile();
String strTime = String.valueOf(DateUtil.getCurrentDateTime().getTime());
if (!setTime(f1, strTime, strTime)) {
//JOptionPane.showMessageDialog(null, "您的体验时间已经到期", strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 0;
}
;
if (!setTime(f2, strTime, strTime)) {
//JOptionPane.showMessageDialog(null, "您的体验时间已经到期", strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 0;
}
;
//JOptionPane.showMessageDialog(null, "您的体验时间还剩30天", strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 30;
}
else {
if (f1.exists() && f2.exists()) {
long l1 = 0;
long l2 = 0;
long l3 = 0;
long l4 = 0;
if (!getStartDate(f1)) {
//JOptionPane.showMessageDialog(null, "您的体验时间已经到期", strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 0;
}
l1 = m_statrTime;
l2 = m_endTime;
if (l1 == 0 || l2 == 0) {
//JOptionPane.showMessageDialog(null, "您的体验时间已经到期", strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 0;
}
if (!getStartDate(f2)) {
//JOptionPane.showMessageDialog(null, "您的体验时间已经到期", strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 0;
}
l3 = m_statrTime;
l4 = m_endTime;
if (l3 == 0 || l4 == 0) {
//JOptionPane.showMessageDialog(null, "您的体验时间已经到期", strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 0;
}
if (l1 != l3 || l2 != l4) {
//JOptionPane.showMessageDialog(null, "您的体验时间已经到期", strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 0;
}
long cur = DateUtil.getCurrentDateTime().getTime();
long diff = cur - l1;
long day = diff / (1000 * 60 * 60 * 24);
if (cur <= l2 || day >= 30) {
//JOptionPane.showMessageDialog(null, "您的体验时间已经到期", strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 0;
}
String strStartTime = String.valueOf(l1);
String strEndTime = String.valueOf(cur);
if (!setTime(f1, strStartTime, strEndTime)) {
//JOptionPane.showMessageDialog(null, "您的体验时间已经到期", strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 0;
}
;
if (!setTime(f2, strStartTime, strEndTime)) {
//JOptionPane.showMessageDialog(null, "您的体验时间已经到期", strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 0;
}
;
//JOptionPane.showMessageDialog(null,
// "您的体验时间还有" + (30 - day) + "天到期,请继续体验",
// strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 30 - day;
}
//JOptionPane.showMessageDialog(null, "您的体验时间已经到期", strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 0;
}
}
catch (IOException ex) {
//JOptionPane.showMessageDialog(null, "您的体验时间已经到期", strTip,
// JOptionPane.INFORMATION_MESSAGE);
return 0;
}
}
public boolean setTime(File file, String strStartTime, String strEndTime) {
if (file == null || strStartTime == null || strEndTime == null) {
return false;
}
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
Random random1 = new Random();
for (int i = 0; i < 50; ++i) {
if (i != 3 && i != 27) {
String strTemp = new String();
strTemp = String.valueOf(random1.nextLong());
bw.write(strTemp);
bw.write("/r/n");
}
if (i == 3) {
bw.write(strStartTime);
bw.write("/r/n");
}
if (i == 27) {
bw.write(strEndTime);
bw.write("/r/n");
}
}
bw.close();
}
catch (IOException ex) {
return false;
}
return true;
}
public boolean getStartDate(File file) {
if (file == null) {
return false;
}
try {
BufferedReader br = new BufferedReader(new FileReader(file));
for (int i = 0; i < 50; ++i) {
String strTemp = br.readLine();
if (i == 3) {
m_statrTime = Long.parseLong(strTemp);
}
if (i == 27) {
m_endTime = Long.parseLong(strTemp);
}
}
br.close();
}
catch (IOException ex) {
return false;
}
return true;
}
public long m_statrTime = 0;
public long m_endTime = 0;
public final static String strTip = "欢迎使用XXX";
}
- 时间限制类
- 逃避时间限制
- Unix中的时间限制
- 去除Lingoes时间限制
- 破解DLL时间限制
- 限制数据库连接时间
- my97datepicker 时间限制
- .NET事务时间限制
- wdatepicker,自定义时间限制
- 时间与系统限制
- wdatapicker 时间限制
- ASP 限制发帖时间 和 登陆限制
- Safengine 试用次数限制 & 试用时间限制
- 使用共享内存的单机操作单位时间限制类
- VB.NET 时间次数限制
- CCS3.3时间限制破解补丁
- ADO.NET连接时间限制
- 给app加上时间限制
- C++经典推荐
- VS2003/VS2005 常用快捷键
- Traits: 类型的else-if-then机制
- 五子棋算法探讨
- 等待对话框类
- 时间限制类
- 爱与喜欢
- 解决A1200手机的zmplayer中文字幕问题
- 基于ARM-uCLinux嵌入式系统的启动引导的分析与设计----此论文本人已发表,转载请注明
- 迟到的感谢——2006最有价值博客的候选人(& 个人回顾)
- 数学之美 系列一 统计语言模型
- 如何编写Linux的设备驱动程序
- Booting Linux from Windows' Boot Manager
- C++中一个奇怪的问题