⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.java

📁 Remote Internet Connect简化了从其它运行操作系统的机子上将一个Linux系统连接到Internet的过程。用户可以用一个简单的GUI加快连接、断开连接、或查看谁在线上。
💻 JAVA
字号:
/*
 * RIC 2 by Harry Otten (c) Copyright 2003 hotten@dds.nl
 * Check out http://www.hotten.dds.nl/ric/

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
USA.
*/

import java.awt.*;
import java.io.*;   // for IOException and Input/OutputStream


public class Config {
	
	private File file;
	private int HOST_PORT;
	private static String 	USERNAME, PASSWORD, HOST, WEARECONNECTEDCOLOR,
					NOBODYCONNECTEDCOLOR, SOMEONCONNECTEDCOLOR, MORECONNECTEDCOLOR;
					
	private static boolean hideFromTaskbar;
	private static boolean ignoreMessages;
	
	private boolean soundEnabled;
	
		
	private FileInputStream in;
	private FileOutputStream out;
	
	private boolean state = false;
	
	public Config() {
		this("RICc.cfg");
	}
	
	public Config(String file) {
		this.file = new File(file);	
	}
		
	public boolean readSettings()
	{
		if (!file.canRead())
			System.out.println("WARNING! Can't read config file "+file.getPath());
		else {
		  	try { 
		  		in = new FileInputStream(file);
		  		int byteRead;
					
				HOST = lees(in);
				System.out.println("host config is:" + HOST);
				USERNAME = lees(in);
				System.out.println("USERNAME config is:" +USERNAME);
				PASSWORD = lees(in);
				System.out.println("PASSWORD config is:" +PASSWORD);
				
				WEARECONNECTEDCOLOR 	= lees(in);
				NOBODYCONNECTEDCOLOR 	= lees(in);
				SOMEONCONNECTEDCOLOR 	= lees(in);
				MORECONNECTEDCOLOR		= lees(in);
				
				byteRead=in.read();
				HOST_PORT=byteRead*256;
				byteRead=in.read();
				HOST_PORT+=byteRead;
				
				System.out.println("Port number is " +HOST_PORT);
				
				// read the ;
				in.read();
				
				if (in.read()==48 ) {
						hideFromTaskbar=false;
				} else hideFromTaskbar=true;
				
				if (in.read()==49 ) {					// if the read false. whe put the ignore on false.
						ignoreMessages=true;		    // the read will fail when a new RIC reads a old config
				} else ignoreMessages=false;
				
				if (in.read()==48 ) {
						soundEnabled=false;
				} else soundEnabled=true;
				
				
				in.close();
				
				state=true;  // The state is okay. Config has been read
				
				return true;
				
			} catch (Exception e) {		
				System.out.println("Read error config file. Deleting the file might help ;-)");
			}
		} 
		
		return false;					
	}
	
	public boolean writeSettings() {
	  	try { 
			if (file.createNewFile())
				System.out.println("New file created: RICc.cfg");
	  		out = new FileOutputStream(file);
	  		
	 	 	out.write(HOST.getBytes());
	 	 	out.write((int)';');
	 	 	out.write(USERNAME.getBytes());
	 	 	out.write((int)';');
	 	 	out.write(PASSWORD.getBytes());
			out.write((int)';');
			out.write(WEARECONNECTEDCOLOR.getBytes());
			out.write((int)';');
			out.write(NOBODYCONNECTEDCOLOR.getBytes());
			out.write((int)';');
			out.write(SOMEONCONNECTEDCOLOR.getBytes());
			out.write((int)';');
			out.write(MORECONNECTEDCOLOR.getBytes());
			out.write((int)';');
			out.write(HOST_PORT / 256);
			out.write(HOST_PORT % 256);
			out.write((int)';');
			if (hideFromTaskbar) {
				out.write(("1").getBytes());
			} else out.write(("0").getBytes());
			if (ignoreMessages) {
				out.write(("1").getBytes());
			} else out.write(("0").getBytes());
			if (soundEnabled) {
				out.write(("1").getBytes());
			} else out.write(("0").getBytes());
			
			out.write((int)';');
			out.close();
			state=true;
			
			return true;
		} catch (Exception e) {		
			System.out.println("Read error config file");
		}
	return false;					
	}

	public String getHost() {
		return HOST;
	}
	public int getHostPort() {
		return HOST_PORT;
	}
	public String getUserName() {	
		return USERNAME;
	}
	public String getPassWord() {
		return PASSWORD;	
	}

	public void setHost(String HOST) {
		this.HOST=HOST;
	}

	public void setHostPort(int HOST_PORT) {
		this.HOST_PORT=HOST_PORT;
	}

	public void setUserName(String USERNAME) {
		this.USERNAME=USERNAME;
	}

	public void setPassWord(String PASSWORD) {
		this.PASSWORD=PASSWORD;
	}
	
	public void setWeAreConnectedColor(String WEARECONNECTEDCOLOR) {
	   this.WEARECONNECTEDCOLOR=WEARECONNECTEDCOLOR;
	}
	
	public void setNobodyConnectedColor(String NOBODYCONNECTEDCOLOR) {
	   this.NOBODYCONNECTEDCOLOR=NOBODYCONNECTEDCOLOR;
	}
	
	public void setSomeonConnectedColor(String SOMEONCONNECTEDCOLOR) {
	   this.SOMEONCONNECTEDCOLOR=SOMEONCONNECTEDCOLOR;
	}
	
	public void setMoreConnectedColor(String MORECONNECTEDCOLOR) {
	   this.MORECONNECTEDCOLOR=MORECONNECTEDCOLOR;
	}
	
	public static String getWeAreConnectedColor() {
	   return WEARECONNECTEDCOLOR;
	}
	
	public static String getNobodyConnectedColor() {
	   return NOBODYCONNECTEDCOLOR;
	}
	
	public String getSomeonConnectedColor() {
	   return SOMEONCONNECTEDCOLOR;
	}
	
	public String getMoreConnectedColor() {
	   return MORECONNECTEDCOLOR;
	}
	
	public static boolean getHideFromTaskbar() {
	   return hideFromTaskbar;
	}
	
	public void setHideFromTaskbar(boolean state) {
	   hideFromTaskbar=state;
	}
	
	public void setIgnoreMessages(boolean state) {
		ignoreMessages=state;	
	}
		
		
	public boolean getSoundEnabled() {
		return soundEnabled;
	}
	
	public void setSoundEnabled(boolean state) {
		soundEnabled=state;	
	}
	
	public boolean getIgnoreMessages() {
		return ignoreMessages;
	}
	
	public void setFile(String file) {
		this.file= new File(file);
	}	
	
	public String getFile() {
		return file.getPath();
	}	
	
	
	public boolean getState() {
		return state;	
	}
	
	private String lees(FileInputStream file) throws Exception {
	 	int byteRead;
		StringBuffer stringBuf= new StringBuffer();

		byteRead=in.read();
		while (byteRead!=(int)';') {
			stringBuf.append((char)byteRead);					
			byteRead=in.read();
		}
	
		/* DEBUG */
		//System.out.println("Gelezen:" + stringBuf.toString());
		
		return stringBuf.toString();
	}		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -