java Source

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            14 Posts :: 24 Stories :: 8 Comments :: 0 Trackbacks
          /*
           * DevicesAutoRegister.java
           * Copyright (C) 2009  <JustinLei@gmail.com>
           *
           *        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.
           *
           
          */
          package org.lambdasoft.device.jmf;

          import java.io.File;
          import java.io.FileOutputStream;
          import java.io.IOException;
          import java.io.InputStream;

          import org.lambdasoft.ui.dialog.BubbleDialog;

          import com.sun.media.util.Registry;

          /**
           * 
          @author lei.tang (justinlei@gmail.com)
           * @date 
           * 
          @version
           
          */
          public class DevicesAutoRegister {
              
          private static DevicesAutoRegister autoRegister;
              
              
          private DevicesAutoRegister() {
              }
               
              
          public static final DevicesAutoRegister getRegister() {
                  
          if(autoRegister == null)
                      autoRegister 
          = new DevicesAutoRegister();
                  
          return autoRegister;
              }
              
              
          public boolean regist(String args[]) throws IOException {
          //查找設備注冊文件在jmf.jar同級目錄
                  File jarFile 
          = new File(Registry.class.getProtectionDomain().getCodeSource().getLocation().getFile());
                  File confFile 
          = new File(jarFile.getParent() + File.separator + "jmf.properties");
                  
          if(confFile.exists()) {
                      
          return true;
                  }
                  writeConfigOrig(confFile);
                  
          return _regist(args == null ? new String[0] : args);
              }
              
              
          private boolean _regist(String args[]){
                  BubbleDialog.getBubble().display(
          "沒有找到設備,開始注冊視頻采集設備",false,false);
                  JMFInit jmfInit 
          = new JMFInit(args);
                  
          boolean flag = jmfInit.isInitialError();
                  jmfInit.dispose();
                  
          if(flag != true)
                      BubbleDialog.getBubble().display(
          "視頻采集設備注冊完畢",false,true);
                  
          else 
                      BubbleDialog.getBubble().display(
          "視頻采集設備注冊失敗,程序將退出",true,true);
                  
          return !flag;
              }
              
              //寫入空的注冊文件(JMF Configure Serializable Object)
              
          private void writeConfigOrig(File file) throws IOException{
                  InputStream is 
          = DevicesAutoRegister.class.getResourceAsStream("jmf.properties.orig");
                  
          byte[] buff = new byte[1024];
                  FileOutputStream os 
          = new FileOutputStream(file);
                  
          while(is.read(buff) != -1) {
                      os.write(buff);
                  }
                  os.flush();
                  os.close();
                  is.close();
              }
          }
          posted on 2010-04-06 16:35 JustinLei 閱讀(1390) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 安丘市| 比如县| 囊谦县| 嘉兴市| 措勤县| 岱山县| 镶黄旗| 尼玛县| 象山县| 石泉县| 繁峙县| 弋阳县| 东丽区| 闸北区| 云梦县| 漳州市| 泸溪县| 独山县| 山东| 甘泉县| 沧州市| 兴城市| 满洲里市| 大城县| 石棉县| 石嘴山市| 永宁县| 桐梓县| 海南省| 东明县| 鸡东县| 阿巴嘎旗| 清水县| 长海县| 六枝特区| 永吉县| 永兴县| 阿鲁科尔沁旗| 辛集市| 拜泉县| 象州县|