java Source

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            14 Posts :: 24 Stories :: 8 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(12)

          我參與的團隊

          搜索

          •  

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

          /*
           * 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 閱讀(1394) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 常德市| 铅山县| 定远县| 金乡县| 广饶县| 庄浪县| 腾冲县| 三河市| 来安县| 隆安县| 城口县| 墨竹工卡县| 栖霞市| 新化县| 江西省| 集贤县| 武鸣县| 弋阳县| 新干县| 云浮市| 吉安县| 天祝| 攀枝花市| 遂川县| 元朗区| 永福县| 唐海县| 磐安县| 安塞县| 信丰县| 安康市| 庐江县| 文昌市| 三江| 南皮县| 永泰县| 盐边县| 九寨沟县| 桃园市| 高雄市| 赤城县|