Changeset 9338 for lang

Show
Ignore:
Timestamp:
04/12/08 08:36:17 (5 years ago)
Author:
tarchan
Message:

lang/java/NanikaKit: 複数 NAR ファイルのインストールに対応

Location:
lang/java/NanikaKit/trunk/src/com/mac/tarchan/nanika
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lang/java/NanikaKit/trunk/src/com/mac/tarchan/nanika/SakuraBalloon.java

    r9332 r9338  
    9494        public SakuraBalloon(String name, NanikaArchive nar) throws IOException 
    9595        { 
     96                log.debug("nar=" + nar); 
    9697                this.name = name; 
    9798//              this.nar = nar; 
    9899 
    99                 File balloonHome = new File(nar.getProperty("balloon.directory")); 
    100                 log.debug("balloon=" + balloonHome); 
     100                String type = nar.getProperty("type"); 
     101                File balloonDir = type.equals("balloon") ? new File("") : new File(nar.getProperty("balloon.directory")); 
     102                log.debug("balloon=" + balloonDir); 
     103                log.debug("balloon=" + new File(balloonDir, nar.getProperty("balloon.descript"))); 
    101104 
    102105                // descript 
    103                 descript = nar.getEntry(new File(balloonHome, nar.getProperty("balloon.descript"))).readDescript(); 
     106                descript = nar.getEntry(new File(balloonDir, nar.getProperty("balloon.descript"))).readDescript(); 
    104107                log.debug("descript=" + descript); 
    105108 
     
    143146                        int x = Integer.parseInt(descript.getProperty("arrow0.x", "0")); 
    144147                        int y = Integer.parseInt(descript.getProperty("arrow0.y", "0")); 
    145                         BufferedImage image = nar.getEntry(new File(balloonHome, nar.getProperty("balloon.arrow0"))).readImage(); 
     148                        BufferedImage image = nar.getEntry(new File(balloonDir, nar.getProperty("balloon.arrow0"))).readImage(); 
    146149                        arrow0 = new SakuraSurface("arrow0", image); 
    147150                        arrow0.setLocation(x, y); 
     
    152155                        int x = Integer.parseInt(descript.getProperty("arrow1.x", "0")); 
    153156                        int y = Integer.parseInt(descript.getProperty("arrow1.y", "0")); 
    154                         BufferedImage image = nar.getEntry(new File(balloonHome, nar.getProperty("balloon.arrow1"))).readImage(); 
     157                        BufferedImage image = nar.getEntry(new File(balloonDir, nar.getProperty("balloon.arrow1"))).readImage(); 
    155158                        arrow1 = new SakuraSurface("arrow1", image); 
    156159                        arrow1.setLocation(x, y); 
     
    161164                        int x = Integer.parseInt(descript.getProperty("onlinemarker.x", "0")); 
    162165                        int y = Integer.parseInt(descript.getProperty("onlinemarker.y", "0")); 
    163                         BufferedImage image = nar.getEntry(new File(balloonHome, nar.getProperty("balloon.onlinemarker"))).readImage(); 
     166                        BufferedImage image = nar.getEntry(new File(balloonDir, nar.getProperty("balloon.onlinemarker"))).readImage(); 
    164167                        onlinemarker = new SakuraSurface("onlinemarker", image); 
    165168                        onlinemarker.setLocation(x, y); 
     
    170173                        int x = Integer.parseInt(descript.getProperty("sstpmarker.x", "0")); 
    171174                        int y = Integer.parseInt(descript.getProperty("sstpmarker.y", "0")); 
    172                         BufferedImage image = nar.getEntry(new File(balloonHome, nar.getProperty("balloon.sstpmarker"))).readImage(); 
     175                        BufferedImage image = nar.getEntry(new File(balloonDir, nar.getProperty("balloon.sstpmarker"))).readImage(); 
    173176                        sstpmarker = new SakuraSurface("sstpmarker", image); 
    174177                        sstpmarker.setLocation(x, y); 
     
    191194                } 
    192195 
    193                 NanikaEntry[] png = nar.list(new File(balloonHome, pat).getPath()); 
     196                NanikaEntry[] png = nar.list(new File(balloonDir, pat).getPath()); 
    194197                log.debug("png=" + png.length + "," + Arrays.toString(png)); 
    195198                Pattern p = Pattern.compile(pat); 
  • lang/java/NanikaKit/trunk/src/com/mac/tarchan/nanika/SakuraGhost.java

    r9332 r9338  
    7878                NanikaArchive newNar = new NanikaArchive(name); 
    7979                if (currentNar == null) currentNar = newNar; 
     80                else currentNar.setNext(newNar); 
     81 
    8082                nar.put(name, newNar); 
    8183                log.debug("nar=" + newNar); 
     
    122124                final SakuraScript sakura = new SakuraScript(); 
    123125                sakura.put("ghost", this); 
     126                sakura.put("system", this); 
    124127                ScheduledExecutorService service = Executors.newScheduledThreadPool(1); 
    125128                service.schedule(new Runnable() 
     
    136139 
    137140        /** 
    138          * オブザーバーに再描画を依頼します。 
    139          */ 
    140         private void repaint() 
     141         * 再描画を依頼します。 
     142         */ 
     143        protected void repaint() 
    141144        { 
    142145                if (observer != null) observer.repaint(); 
     
    191194        private void loadBalloon() 
    192195        { 
    193                 currentNar.getBalloon(); 
     196//              currentNar.getBalloon(); 
    194197                String name="name"; 
    195198                String craftman = "craftman"; 
  • lang/java/NanikaKit/trunk/src/com/mac/tarchan/nanika/SakuraShell.java

    r9332 r9338  
    158158                { 
    159159                        // balloon 
    160                         balloon = new SakuraBalloon(name, nar); 
     160//                      balloon = new SakuraBalloon(name, nar); 
     161                        balloon = nar.getBalloon(name); 
    161162 
    162163                        // balloon offset 
     
    169170                        balloon.setAlignment(align); 
    170171                } 
    171                 catch (IOException e) 
    172                 { 
    173                         log.error("read balloon error", e); 
    174                 } 
     172//              catch (IOException e) 
     173//              { 
     174//                      log.error("read balloon error", e); 
     175//              } 
    175176                catch (Exception e) 
    176177                { 
  • lang/java/NanikaKit/trunk/src/com/mac/tarchan/nanika/nar/NanikaArchive.java

    r9332 r9338  
    1111import java.io.File; 
    1212import java.io.FileFilter; 
     13import java.io.FileNotFoundException; 
    1314import java.io.IOException; 
    1415import java.util.LinkedList; 
     
    2223import org.apache.commons.logging.LogFactory; 
    2324 
     25import com.mac.tarchan.nanika.SakuraBalloon; 
    2426import com.mac.tarchan.nanika.SakuraSurface; 
    2527 
     
    3638        private static final Log log = LogFactory.getLog(NanikaArchive.class); 
    3739 
    38         /** NAR ファイル */ 
    39         protected NanikaArchive parent; 
     40        /** 次候補 NAR ファイル */ 
     41        protected NanikaArchive alt; 
    4042 
    4143        /** ZIP ファイル */ 
     
    4345 
    4446        /** プロパティー */ 
    45         protected Properties properties = new Properties(getDefaults()); 
     47        protected Properties descript = new Properties(getDefaults()); 
    4648 
    4749        /** 
     
    6466 
    6567                NanikaEntry install = getEntry(getProperty("nanika.install")); 
    66                 if (install != null) 
    67                 { 
    68                         Properties installDesc = install.readDescript(); 
    69                         log.debug("install=" + installDesc); 
    70                         properties.putAll(installDesc); 
    71                 } 
     68                if (install == null) throw new FileNotFoundException(getProperty("nanika.install")); 
     69 
     70                Properties installDesc = install.readDescript(); 
     71                descript.putAll(installDesc); 
     72//              descript.setProperty(installDesc.getProperty("type") + ".directory", installDesc.getProperty("directory")); 
     73                log.debug("install=" + descript); 
    7274 
    7375                NanikaEntry ghost = getEntry(new File(getGhostHome(), getProperty("ghost.descript"))); 
     
    7880 
    7981        /** 
     82         * 次のアーカイブを設定します。 
     83         *  
     84         * @param nar 次のアーカイブ 
     85         * @return このアーカイブへの参照 
     86         */ 
     87        public NanikaArchive setNext(NanikaArchive nar) 
     88        { 
     89                this.alt = nar; 
     90                return this; 
     91        } 
     92 
     93        /** 
    8094         * デフォルトのプロパティーを返します。 
    8195         *  
     
    97111 
    98112                // shell 
    99                 defaults.setProperty("shell.root", "shell"); 
    100                 defaults.setProperty("shell.home", "master"); 
     113                defaults.setProperty("shell.directory", new File("shell", "master").getPath()); 
    101114                defaults.setProperty("shell.descript", "descript.txt"); 
    102115                defaults.setProperty("shell.surfaces", "surfaces.txt"); 
     
    107120                defaults.setProperty("balloon.arrow0", "arrow0.png"); 
    108121                defaults.setProperty("balloon.arrow1", "arrow1.png"); 
    109                 defaults.setProperty("balloon.onlinemarker", "online.png"); 
     122                defaults.setProperty("balloon.onlinemarker", "online0.png"); 
    110123                defaults.setProperty("balloon.sstpmarker", "sstp.png"); 
    111124 
     
    124137        public Properties getProperties() 
    125138        { 
    126                 return properties; 
     139                return descript; 
    127140        } 
    128141 
     
    135148        public String getProperty(String key) 
    136149        { 
    137                 return properties.getProperty(key); 
     150                return descript.getProperty(key); 
    138151        } 
    139152 
     
    151164        { 
    152165                Properties props = getProperties(); 
    153                 File shellHome = new File(props.getProperty("ghost.root"), props.getProperty("ghost.directory")); 
     166                File shellHome = new File(props.getProperty("ghost.directory")); 
    154167                return shellHome; 
    155168        } 
     
    163176        { 
    164177                Properties props = getProperties(); 
    165                 File shellHome = new File(props.getProperty("shell.root"), props.getProperty("shell.home")); 
     178                File shellHome = new File(props.getProperty("shell.directory")); 
    166179                return shellHome; 
    167180        } 
     
    186199        public NanikaEntry getEntry(File file) 
    187200        { 
    188                 ZipEntry zipEntry = zip.getEntry(file.getPath()); 
     201                String path = file.getPath(); 
     202                if (path.startsWith("/")) path = path.substring(1); 
     203                ZipEntry zipEntry = zip.getEntry(path); 
    189204//              log.debug("zipEntry=" + zipEntry); 
    190205                return zipEntry != null ? new NanikaEntry(zip, zipEntry) : null; 
     
    199214        public NanikaEntry[] list(String regex) 
    200215        { 
     216                if (regex.startsWith("/")) regex = regex.substring(1); 
    201217                log.debug("regex=" + regex); 
    202218                java.util.Enumeration<? extends ZipEntry> in = zip.entries(); 
     
    258274        /** 
    259275         * バルーンを取得します。 
    260          */ 
    261         public void getBalloon() 
     276         *  
     277         * @param name sakura または kero 
     278         * @return バルーン 
     279         */ 
     280        public SakuraBalloon getBalloon(String name) 
    262281        { 
    263282                try 
    264283                { 
    265                         File home = new File(getProperty("balloon.directory")); 
    266                         log.debug("balloon=" + home); 
    267                         NanikaEntry descript = getEntry(new File(home, getProperty("balloon.descript"))); 
    268                         if (descript == null) return; 
    269                         descript.readDescript(); 
    270                         NanikaEntry balloons0 = getEntry(new File(home, "balloons0.png")); 
    271                         if (balloons0 == null) return; 
    272                         balloons0.readImage(); 
    273                 } 
    274                 catch (IOException e) 
    275                 { 
     284                        return new SakuraBalloon(name, this); 
     285                } 
     286                catch (Exception e) 
     287                { 
     288                        if (alt != null) 
     289                        { 
     290                                log.trace("alt=" + alt); 
     291                                return alt.getBalloon(name); 
     292                        } 
     293 
    276294                        log.error("read balloon error", e); 
     295                        return null; 
    277296                } 
    278297        } 
     
    317336                } 
    318337        } 
     338 
     339        /** 
     340         * NAR ファイルの文字列表現を返します。 
     341         *  
     342         * @return NAR ファイルの文字列表現 
     343         */ 
     344        public String toString() 
     345        { 
     346                return new StringBuilder() 
     347                        .append("type=" + getProperty("type")) 
     348                        .append(", name=" + getProperty("name")) 
     349                        .append(", directory=" + getProperty("directory")) 
     350                        .toString(); 
     351        } 
    319352} 
  • lang/java/NanikaKit/trunk/src/com/mac/tarchan/nanika/nar/NanikaEntry.java

    r9091 r9338  
    102102                        out.println(line); 
    103103                } 
     104                reader.close(); 
    104105 
    105106                return buf.toString();