├── .project ├── LICENSE ├── README.md ├── bin ├── linux │ ├── card-admin.jar │ ├── configuration.properties │ └── startCardAdmin.sh └── windows │ ├── TonuinoCardAdmin.exe │ ├── configuration.properties │ └── shell │ ├── card-admin.jar │ ├── configuration.properties │ └── startCardAdmin.cmd ├── card-admin ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ ├── main │ ├── java │ │ ├── META-INF │ │ │ └── MANIFEST.MF │ │ └── at │ │ │ └── dcosta │ │ │ └── tonuino │ │ │ └── cardadmin │ │ │ ├── CardFilesystemAnalyzer.java │ │ │ ├── IndexGenerator.java │ │ │ ├── Main.java │ │ │ ├── Mp3Player.java │ │ │ ├── Track.java │ │ │ ├── TrackListener.java │ │ │ ├── UpdateableDialog.java │ │ │ ├── idtags │ │ │ └── TagIO.java │ │ │ ├── ui │ │ │ ├── Direction.java │ │ │ ├── DirectorySelectionListener.java │ │ │ ├── ErrorDisplay.java │ │ │ ├── FilesystemView.java │ │ │ ├── FolderTree.java │ │ │ ├── ModalDialog.java │ │ │ ├── MultilineTextDialog.java │ │ │ ├── TableHeader.java │ │ │ ├── TrackTableModel.java │ │ │ ├── ValueAdapter.java │ │ │ └── ValueResolver.java │ │ │ └── util │ │ │ ├── Configuration.java │ │ │ ├── ExceptionUtil.java │ │ │ ├── FileNames.java │ │ │ ├── LogUtil.java │ │ │ ├── StreamGobbler.java │ │ │ └── TrackSorter.java │ └── resources │ │ ├── configuration.properties │ │ ├── images │ │ ├── card-admin.ico │ │ ├── card-admin.png │ │ ├── card-admin.xcf │ │ ├── down.png │ │ ├── play.png │ │ └── up.png │ │ ├── launch4j.cfg.xml │ │ └── start.cmd │ └── site │ └── site.xml └── screenshot.png /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | cardadmin 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coschtl/tonuino-cardadmin/8ad9699ba7f6cae11c3661730f64d41f7fd2cc06/README.md -------------------------------------------------------------------------------- /bin/linux/card-admin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coschtl/tonuino-cardadmin/8ad9699ba7f6cae11c3661730f64d41f7fd2cc06/bin/linux/card-admin.jar -------------------------------------------------------------------------------- /bin/linux/configuration.properties: -------------------------------------------------------------------------------- 1 | # normalizing program 2 | # if not set, no normalizing can be done 3 | #mp3.normalizing.commandline=C:\\Program Files (x86)\\MP3Gain\\mp3gain.exe 4 | #mp3.normalizing.options = /a /k 5 | 6 | # alternative card-roots 7 | # i.e. for using a local folder as card-backup 8 | alternative.card.root = /home/stephan/Tonuino/SD-Karte 9 | 10 | # default content root 11 | default.content.root = /home/stephan/Musik 12 | 13 | # index file location 14 | card-index.location = /home/stephan/Tonuino/SD-Karten-Index 15 | # set to csv to generate csv files 16 | # any other string (or no value) will generate human readable files 17 | card-index.format = csv -------------------------------------------------------------------------------- /bin/linux/startCardAdmin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export cardAdminConfigFile=./configuration.properties 3 | java -jar card-admin.jar 4 | -------------------------------------------------------------------------------- /bin/windows/TonuinoCardAdmin.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coschtl/tonuino-cardadmin/8ad9699ba7f6cae11c3661730f64d41f7fd2cc06/bin/windows/TonuinoCardAdmin.exe -------------------------------------------------------------------------------- /bin/windows/configuration.properties: -------------------------------------------------------------------------------- 1 | # normalizing program 2 | # if not set, no normalizing can be done 3 | mp3.normalizing.commandline=C:\\Program Files (x86)\\MP3Gain\\mp3gain.exe 4 | mp3.normalizing.options = /a /k 5 | 6 | # alternative card-roots 7 | # i.e. for using a local folder as card-backup 8 | alternative.card.root = D:/media/Tonuino/SD-Karte 9 | 10 | # default content root 11 | default.content.root = D:/media/Tonuino/Content 12 | 13 | # index file location 14 | card-index.location = D:/media/Tonuino/SD-Karten-Index 15 | # set to csv to generate csv files 16 | # any other string (or no value) will generate human readable files 17 | card-index.format = csv -------------------------------------------------------------------------------- /bin/windows/shell/card-admin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coschtl/tonuino-cardadmin/8ad9699ba7f6cae11c3661730f64d41f7fd2cc06/bin/windows/shell/card-admin.jar -------------------------------------------------------------------------------- /bin/windows/shell/configuration.properties: -------------------------------------------------------------------------------- 1 | # normalizing program 2 | # if not set, no normalizing can be done 3 | mp3.normalizing.commandline=C:\\Program Files (x86)\\MP3Gain\\mp3gain.exe 4 | mp3.normalizing.options = /a /k 5 | 6 | # alternative card-roots 7 | # i.e. for using a local folder as card-backup 8 | alternative.card.root = D:/media/Tonuino/SD-Karte 9 | 10 | # default content root 11 | default.content.root = D:/media/Tonuino/Content 12 | 13 | # index file location 14 | card-index.location = D:/media/Tonuino/SD-Karten-Index -------------------------------------------------------------------------------- /bin/windows/shell/startCardAdmin.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | set cardAdminConfigFile=./configuration.properties 3 | 4 | if not defined java_location ( 5 | if not defined java_home ( 6 | set java_location=D:\development\apps\jdk1.8.0_201 7 | ) else ( 8 | set java_location=%java_home% 9 | ) 10 | ) 11 | 12 | rem ######################################################## 13 | 14 | %java_location%\bin\java -jar card-admin.jar -------------------------------------------------------------------------------- /card-admin/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /card-admin/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /card-admin/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | card-admin 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /card-admin/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /card-admin/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /card-admin/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /card-admin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | at.dcosta.tonuino 9 | card-admin 10 | 0.3.0 11 | 12 | card-admin 13 | A simple card-admin. 14 | 15 | 16 | UTF-8 17 | 1.8 18 | 1.8 19 | 20 | 21 | 22 | 23 | com.mpatric 24 | mp3agic 25 | 0.9.1 26 | 27 | 28 | javazoom 29 | jlayer 30 | 1.0.1 31 | 32 | 33 | junit 34 | junit 35 | 3.8.1 36 | 37 | 38 | 39 | 40 | 42 | 43 | 44 | maven-clean-plugin 45 | 3.1.0 46 | 47 | 48 | maven-site-plugin 49 | 3.7.1 50 | 51 | 52 | maven-project-info-reports-plugin 53 | 3.0.0 54 | 55 | 56 | 57 | maven-resources-plugin 58 | 3.0.2 59 | 60 | 61 | maven-compiler-plugin 62 | 3.8.0 63 | 64 | 65 | maven-surefire-plugin 66 | 2.22.1 67 | 68 | 69 | maven-jar-plugin 70 | 3.0.2 71 | 72 | 73 | 74 | true 75 | lib/ 76 | at.dcosta.tonuino.cardadmin.Main 77 | 78 | 79 | 80 | 81 | 82 | maven-install-plugin 83 | 2.5.2 84 | 85 | 86 | maven-deploy-plugin 87 | 2.8.2 88 | 89 | 90 | 91 | 92 | 93 | 94 | maven-assembly-plugin 95 | 3.3.0 96 | 97 | 98 | 99 | at.dcosta.tonuino.cardadmin.Main 100 | 101 | 102 | 103 | jar-with-dependencies 104 | 105 | false 106 | 107 | 108 | 109 | package 110 | 111 | single 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | maven-project-info-reports-plugin 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /card-admin/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Main-Class: at.dcosta.tonuino.cardadmin.Main -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/CardFilesystemAnalyzer.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin; 2 | 3 | import static at.dcosta.tonuino.cardadmin.util.FileNames.SYSTEM_FOLDERS; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.lang.System.Logger; 8 | import java.nio.file.Files; 9 | import java.nio.file.Path; 10 | import java.nio.file.Paths; 11 | import java.util.ArrayList; 12 | import java.util.HashMap; 13 | import java.util.Iterator; 14 | import java.util.List; 15 | import java.util.Map; 16 | import java.util.TreeMap; 17 | 18 | import at.dcosta.tonuino.cardadmin.util.FileNames; 19 | import at.dcosta.tonuino.cardadmin.util.FileNames.Type; 20 | import at.dcosta.tonuino.cardadmin.util.LogUtil; 21 | import at.dcosta.tonuino.cardadmin.util.TrackSorter; 22 | 23 | public class CardFilesystemAnalyzer { 24 | 25 | public static class RequiredAction { 26 | public enum Action { 27 | DELETE, ADD, RENAME; 28 | } 29 | 30 | public static RequiredAction DELETE = new RequiredAction(Action.DELETE); 31 | public static RequiredAction ADD = new RequiredAction(Action.ADD); 32 | 33 | public static RequiredAction createRenameAction(String newName) { 34 | return new RequiredAction(Action.RENAME, newName); 35 | } 36 | 37 | private final Action action; 38 | private String additionalInfo; 39 | 40 | private RequiredAction(Action action) { 41 | this.action = action; 42 | } 43 | 44 | private RequiredAction(Action action, String additionalInfo) { 45 | this.action = action; 46 | this.additionalInfo = additionalInfo; 47 | } 48 | 49 | public Action getAction() { 50 | return action; 51 | } 52 | 53 | public String getAdditionalInfo() { 54 | return additionalInfo; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | if (additionalInfo == null) { 60 | return action.toString(); 61 | } 62 | return action.toString() + " to " + additionalInfo; 63 | } 64 | } 65 | 66 | private static final Logger LOGGER = System.getLogger(TrackSorter.class.getName()); 67 | 68 | public static Map analyzeRoot(Path root) throws IOException { 69 | Map changes = new TreeMap<>(); 70 | Files.list(root).forEach(path -> { 71 | String filename = path.getFileName().toString(); 72 | if (!SYSTEM_FOLDERS.contains(filename) && !Type.FOLDER.getPattern().matcher(filename).matches()) { 73 | System.out.println(filename + " no match: " + Type.FOLDER.getPattern().pattern()); 74 | changes.put(path, RequiredAction.DELETE); 75 | } 76 | }); 77 | SYSTEM_FOLDERS.forEach(folder -> { 78 | Path path = Path.of(root.toString(), folder); 79 | if (!path.toFile().isDirectory()) { 80 | changes.put(path, RequiredAction.ADD); 81 | } 82 | }); 83 | return changes; 84 | } 85 | 86 | public static Map correctFolders(Path root, boolean simulate) throws IOException { 87 | Map changes = new TreeMap<>(); 88 | Files.list(root).forEach(folder -> { 89 | if (Type.FOLDER.getPattern().matcher(folder.getFileName().toString()).matches()) { 90 | try { 91 | correctFolder(folder, changes, simulate); 92 | } catch (IOException e) { 93 | throw new RuntimeException(e); 94 | } 95 | } 96 | }); 97 | return changes; 98 | } 99 | 100 | public static String toGermanText(Map changes) { 101 | StringBuilder b = new StringBuilder(); 102 | changes.entrySet().forEach(e -> { 103 | b.append(e.getKey()); 104 | RequiredAction action = e.getValue(); 105 | switch (action.getAction()) { 106 | case ADD: 107 | b.append( " fehlt\n"); 108 | break; 109 | case DELETE: 110 | b.append( " muss gelöscht werden\n"); 111 | break; 112 | case RENAME: 113 | b.append( " muss"); 114 | if (action.getAdditionalInfo() != null) { 115 | b.append(" nach ").append(action.getAdditionalInfo()); 116 | } 117 | b.append(" umbenannt werden\n"); 118 | break; 119 | } 120 | }); 121 | return b.toString(); 122 | } 123 | 124 | private static void correctFolder(Path folder, Map changes, boolean simulate) throws IOException { 125 | List tracks = new ArrayList<>(); 126 | Files.list(folder).forEach(filePath -> { 127 | File file = filePath.toFile(); 128 | if (file.isDirectory()) { 129 | if (!simulate) { 130 | file.delete(); 131 | } 132 | changes.put( filePath, RequiredAction.DELETE); 133 | } else { 134 | String filename = filePath.getFileName().toString(); 135 | if (!Type.FILE.getPattern().matcher(filename).matches()) { 136 | if (!simulate) { 137 | file.delete(); 138 | } 139 | changes.put( filePath, RequiredAction.createRenameAction(null)); 140 | } else { 141 | tracks.add(filePath); 142 | } 143 | } 144 | }); 145 | correctFilenames(tracks, changes, simulate); 146 | } 147 | 148 | private static void correctFilenames(List paths, Map changes, boolean simulate) { 149 | if (paths.isEmpty()) { 150 | return; 151 | } 152 | Map renames = new HashMap<>(); 153 | Iterator newPaths = FileNames.createNewFileNameSeries(paths.get(0).getParent()); 154 | paths.forEach(path -> { 155 | Path newPath = newPaths.next(); 156 | LogUtil.trace(LOGGER, "path: ", path, " - should be: ", newPath); 157 | if (!newPath.equals(path)) { 158 | Path tmpPath = Paths.get(path.toString() + ".tmp"); 159 | try { 160 | if (!simulate) { 161 | Files.move(path, tmpPath); 162 | } 163 | } catch (IOException ex) { 164 | throw new RuntimeException(ex); 165 | } 166 | LogUtil.debug(LOGGER, "rename1: ", path, " -> ", tmpPath); 167 | renames.put(tmpPath, newPath); 168 | } 169 | }); 170 | renames.entrySet().forEach(e -> { 171 | try { 172 | if (!simulate) { 173 | Files.move(e.getKey(), e.getValue()); 174 | } 175 | String origName = e.getKey().toString(); 176 | changes.put( Paths.get(origName.substring(0, origName.length()-4)), RequiredAction.createRenameAction(e.getValue().toString())); 177 | LogUtil.debug(LOGGER, "rename2: ", e.getKey(), " -> ", e.getValue()); 178 | } catch (IOException ex) { 179 | throw new RuntimeException(ex); 180 | } 181 | }); 182 | } 183 | 184 | } 185 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/IndexGenerator.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin; 2 | 3 | import java.awt.Desktop; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.io.PrintStream; 7 | import java.lang.System.Logger; 8 | import java.nio.file.Files; 9 | import java.nio.file.Path; 10 | import java.util.List; 11 | import java.util.stream.Collectors; 12 | 13 | import com.mpatric.mp3agic.InvalidDataException; 14 | import com.mpatric.mp3agic.UnsupportedTagException; 15 | 16 | import at.dcosta.tonuino.cardadmin.util.Configuration; 17 | import at.dcosta.tonuino.cardadmin.util.FileNames; 18 | import at.dcosta.tonuino.cardadmin.util.FileNames.Type; 19 | import at.dcosta.tonuino.cardadmin.util.LogUtil; 20 | import at.dcosta.tonuino.cardadmin.util.TrackSorter; 21 | 22 | public class IndexGenerator { 23 | 24 | public enum IndexFormat { 25 | CSV, HUMAN_READABLE; 26 | } 27 | 28 | private class FolderDescription { 29 | private final int folderNumber; 30 | private final String folderName; 31 | 32 | public FolderDescription(int folderNumber, String folderName) { 33 | this.folderNumber=folderNumber; 34 | this.folderName=folderName; 35 | } 36 | public String getFolderName() { 37 | return folderName; 38 | } 39 | public int getFolderNumber() { 40 | return folderNumber; 41 | } 42 | } 43 | private static final Logger LOGGER = System.getLogger(IndexGenerator.class.getName()); 44 | 45 | private final IndexFormat format; 46 | 47 | public IndexGenerator(IndexFormat format) { 48 | this.format = format; 49 | } 50 | 51 | public void createIndexfile(Path root) throws IOException { 52 | File folder = new File( Configuration.getInstance().getCardIndexLocation()); 53 | String suffix = format == IndexFormat.CSV ? ".csv" : ".txt"; 54 | File indexFile =new File(folder, FileNames.createDateFileName("index", suffix)); 55 | PrintStream out= new PrintStream(indexFile); 56 | if (format == IndexFormat.CSV) { 57 | out.println("directoryNumber,fileNumber,directoryName,subdirectoryName,title,tags,runtime"); 58 | } 59 | Files.list(root).forEach(path -> { 60 | String filename = path.getFileName().toString(); 61 | if (Type.FOLDER.getPattern().matcher(filename).matches()) { 62 | try { 63 | addFolderToIndex(path, out); 64 | } catch (IOException e) { 65 | LogUtil.error(LOGGER, "Can not read Track from", path,": ", e); 66 | } 67 | } 68 | }); 69 | out.flush(); 70 | out.close(); 71 | Desktop.getDesktop().open(indexFile); 72 | } 73 | 74 | private void addFolderToIndex(Path path, PrintStream out) throws IOException { 75 | List tracks = Files.list(path) 76 | .filter(file -> file.getFileName().toString().toLowerCase().endsWith(FileNames.SUFFIX_MP3)) 77 | .map(file -> { 78 | try { 79 | return new Track(file); 80 | } catch (UnsupportedTagException | InvalidDataException | IOException e) { 81 | LogUtil.error(LOGGER, "Can not read Tracks: ", e); 82 | return null; 83 | } 84 | }).filter(track -> track != null).collect(Collectors.toList()); 85 | if (tracks.isEmpty()) { 86 | return; 87 | } 88 | TrackSorter.sortByFilename(tracks); 89 | FolderDescription folderDescription = new FolderDescription(Integer.parseInt(path.getFileName().toString()), tracks.get(0).getAlbum()); 90 | printFoderHeader(folderDescription, out); 91 | int i=1; 92 | for (Track t: tracks ) { 93 | printTrack(i, t, folderDescription, out); 94 | i++; 95 | }; 96 | printFolderFooter(out); 97 | } 98 | 99 | private void printFoderHeader (FolderDescription folderDescription, PrintStream out) { 100 | if (format == IndexFormat.HUMAN_READABLE) { 101 | out.println(folderDescription.getFolderNumber() + " - " + folderDescription.getFolderName() + ":\n"); 102 | } 103 | } 104 | 105 | private void printTrack (int trackNumber, Track track, FolderDescription folderDescription, PrintStream out) { 106 | if (format == IndexFormat.HUMAN_READABLE) { 107 | if (trackNumber <10) { 108 | out.print(" "); 109 | } 110 | out.print(trackNumber); 111 | out.print(". "); 112 | out.println(track.getTitle()); 113 | } else { 114 | out.print(folderDescription.getFolderNumber()); 115 | out.print(","); 116 | out.print(trackNumber); 117 | addMasked(folderDescription.getFolderName(), out); 118 | addMasked(folderDescription.getFolderName(), out); 119 | addMasked(track.getTitle(), out); 120 | addMasked(track.getArtist(), out); 121 | out.print(","); 122 | out.println(track.getLengthInSeconds()); 123 | } 124 | } 125 | 126 | private void addMasked(String s, PrintStream out) { 127 | if (s != null) { 128 | out.print(','); 129 | out.print('"'); 130 | out.print(s.replaceAll("\"", "\"\"")); 131 | out.print('"'); 132 | } else { 133 | out.print(','); 134 | } 135 | } 136 | 137 | private void printFolderFooter (PrintStream out) { 138 | if (format == IndexFormat.HUMAN_READABLE) { 139 | out.println("-------------------------------------------\n"); 140 | out.println(); 141 | } 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/Main.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.swing.JFrame; 6 | import javax.swing.UIManager; 7 | import javax.swing.UnsupportedLookAndFeelException; 8 | 9 | import at.dcosta.tonuino.cardadmin.ui.FilesystemView; 10 | 11 | public class Main { 12 | 13 | public static void main(String[] args) throws IOException { 14 | try { 15 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 16 | JFrame.setDefaultLookAndFeelDecorated(true); 17 | } catch (ClassNotFoundException | InstantiationException | IllegalAccessException 18 | | UnsupportedLookAndFeelException e) { 19 | e.printStackTrace(); 20 | } 21 | new FilesystemView().show(); 22 | } 23 | 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/Mp3Player.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.Files; 5 | import java.nio.file.StandardOpenOption; 6 | 7 | import javax.swing.SwingWorker; 8 | 9 | import javazoom.jl.decoder.JavaLayerException; 10 | import javazoom.jl.player.advanced.AdvancedPlayer; 11 | import javazoom.jl.player.advanced.PlaybackListener; 12 | 13 | public class Mp3Player { 14 | private static class PlayerThread extends SwingWorker { 15 | 16 | private AdvancedPlayer player; 17 | 18 | public PlayerThread(Track track) { 19 | try { 20 | player = new AdvancedPlayer(Files.newInputStream(track.getPath(), StandardOpenOption.READ)); 21 | player.setPlayBackListener(new PlaybackListener() { 22 | }); 23 | } catch (JavaLayerException | IOException e) { 24 | System.out 25 | .println("Can not play " + track.getTitle() + " (" + track.getPath() + "): " + e.getMessage()); 26 | } 27 | } 28 | 29 | @Override 30 | protected Void doInBackground() throws Exception { 31 | player.play(); 32 | return null; 33 | } 34 | 35 | @Override 36 | protected void done() { 37 | super.done(); 38 | } 39 | 40 | public void stop() { 41 | player.stop(); 42 | } 43 | 44 | } 45 | 46 | private PlayerThread playerThread; 47 | 48 | public void play(Track track) { 49 | playerThread = new PlayerThread(track); 50 | playerThread.execute(); 51 | 52 | } 53 | 54 | public boolean isPlaying() { 55 | return playerThread != null && !playerThread.isDone(); 56 | } 57 | 58 | public void stop() { 59 | if (isPlaying()) { 60 | playerThread.stop(); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/Track.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.nio.file.Files; 6 | import java.nio.file.Path; 7 | import java.nio.file.StandardCopyOption; 8 | import java.util.Objects; 9 | 10 | import com.mpatric.mp3agic.ID3v1; 11 | import com.mpatric.mp3agic.ID3v1Tag; 12 | import com.mpatric.mp3agic.ID3v2; 13 | import com.mpatric.mp3agic.InvalidDataException; 14 | import com.mpatric.mp3agic.Mp3File; 15 | import com.mpatric.mp3agic.NotSupportedException; 16 | import com.mpatric.mp3agic.UnsupportedTagException; 17 | 18 | public class Track { 19 | private final Mp3File mp3File; 20 | private final Path path; 21 | 22 | private String album; 23 | private String artist; 24 | private String title; 25 | private int trackNumber; 26 | private ID3v1 tag; 27 | private boolean modified; 28 | private long lengthInSeconds; 29 | private TrackListener listener; 30 | 31 | public Track(Path path) throws UnsupportedTagException, InvalidDataException, IOException { 32 | this.path = path; 33 | this.mp3File = new Mp3File(path); 34 | 35 | if (mp3File.hasId3v2Tag()) { 36 | tag = mp3File.getId3v2Tag(); 37 | } else if (mp3File.hasId3v1Tag()) { 38 | tag = mp3File.getId3v1Tag(); 39 | } 40 | if (tag != null) { 41 | album = tag.getAlbum(); 42 | artist = tag.getArtist(); 43 | title = tag.getTitle(); 44 | if (title == null || title.isBlank()) { 45 | setTitle(path.getFileName().toString()); 46 | } 47 | String trackNo = tag.getTrack(); 48 | int trackNumberInt = 0; 49 | if (trackNo != null) { 50 | try { 51 | trackNumberInt = Integer.parseInt(trackNo); 52 | } catch (Exception e) { 53 | // ignore 54 | } 55 | } 56 | trackNumber = trackNumberInt; 57 | } else { 58 | tag = new ID3v1Tag(); 59 | mp3File.setId3v1Tag(tag); 60 | album = null; 61 | artist = null; 62 | setTitle(path.toFile().getName()); 63 | trackNumber = 0; 64 | setModified(); 65 | } 66 | lengthInSeconds = mp3File.getLengthInSeconds(); 67 | } 68 | 69 | public long getLengthInSeconds() { 70 | return lengthInSeconds; 71 | } 72 | 73 | public Path getPath() { 74 | return path; 75 | } 76 | 77 | public String getAlbum() { 78 | return album; 79 | } 80 | 81 | public String getArtist() { 82 | return artist; 83 | } 84 | 85 | public String getTitle() { 86 | return title; 87 | } 88 | 89 | public int getTrackNumber() { 90 | return trackNumber; 91 | } 92 | 93 | public void setAlbum(String album) { 94 | if (!Objects.equals(album, this.album)) { 95 | setModified(); 96 | } 97 | this.album = album; 98 | tag.setAlbum(album); 99 | } 100 | 101 | public void setArtist(String artist) { 102 | if (!Objects.equals(artist, this.artist)) { 103 | setModified(); 104 | } 105 | this.artist = artist; 106 | tag.setArtist(artist); 107 | } 108 | 109 | public void setTitle(String title) { 110 | if (!Objects.equals(title, this.title)) { 111 | setModified(); 112 | } 113 | this.title = title; 114 | tag.setTitle(title); 115 | } 116 | 117 | public void setTrackNumber(int trackNumber) { 118 | if (trackNumber != this.trackNumber) { 119 | setModified(); 120 | } 121 | this.trackNumber = trackNumber; 122 | tag.setTrack(Integer.toString(trackNumber)); 123 | } 124 | 125 | public void writeTo(String path, boolean forceWrite) 126 | throws UnsupportedTagException, InvalidDataException, IOException, NotSupportedException { 127 | if (!isModified() && !forceWrite) { 128 | return; 129 | } 130 | if (tag instanceof ID3v2) { 131 | mp3File.setId3v2Tag((ID3v2) tag); 132 | } else { 133 | mp3File.setId3v1Tag(tag); 134 | } 135 | mp3File.save(path); 136 | } 137 | 138 | public void save() throws IOException, UnsupportedTagException, InvalidDataException, NotSupportedException { 139 | if (!isModified()) { 140 | return; 141 | } 142 | Path tmp = File.createTempFile(getPath().getFileName().toString(), ".tmp").toPath(); 143 | writeTo(tmp.toString(),false); 144 | Files.move(tmp, getPath(), StandardCopyOption.REPLACE_EXISTING); 145 | } 146 | 147 | @Override 148 | public String toString() { 149 | return "Track [path=" + path + ", album=" + album + ", artist=" + artist + ", title=" + title + ", trackNumber=" 150 | + trackNumber + "]"; 151 | } 152 | 153 | public Track setTrackListener(TrackListener listener) { 154 | this.listener = listener; 155 | if (modified) { 156 | listener.trackChanged(this); 157 | } 158 | return this; 159 | } 160 | 161 | public boolean isModified() { 162 | return modified; 163 | } 164 | 165 | private void setModified() { 166 | modified = true; 167 | if (listener != null) { 168 | listener.trackChanged(this); 169 | } 170 | } 171 | 172 | } 173 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/TrackListener.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin; 2 | 3 | public interface TrackListener { 4 | void trackChanged(Track track); 5 | 6 | } 7 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/UpdateableDialog.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin; 2 | 3 | public interface UpdateableDialog { 4 | void updateText(String newText); 5 | } 6 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/idtags/TagIO.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.idtags; 2 | 3 | public interface TagIO { 4 | 5 | 6 | 7 | } 8 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/ui/Direction.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.ui; 2 | 3 | public enum Direction { 4 | 5 | DOWN, UP, FIRST, LAST; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/ui/DirectorySelectionListener.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.ui; 2 | 3 | import java.io.File; 4 | 5 | public interface DirectorySelectionListener { 6 | void pathSelected(File path); 7 | } 8 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/ui/ErrorDisplay.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.ui; 2 | 3 | public interface ErrorDisplay { 4 | 5 | void showError(String summary, String detail); 6 | 7 | void showError(String summary, Throwable t); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/ui/FilesystemView.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.ui; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Color; 5 | import java.awt.Component; 6 | import java.awt.FlowLayout; 7 | import java.awt.Font; 8 | import java.awt.Insets; 9 | import java.awt.Point; 10 | import java.awt.event.ActionEvent; 11 | import java.awt.event.ActionListener; 12 | import java.awt.event.MouseAdapter; 13 | import java.awt.event.MouseEvent; 14 | import java.io.File; 15 | import java.io.IOException; 16 | import java.nio.file.Path; 17 | import java.nio.file.Paths; 18 | import java.util.Iterator; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import javax.swing.BoxLayout; 23 | import javax.swing.ImageIcon; 24 | import javax.swing.JButton; 25 | import javax.swing.JFileChooser; 26 | import javax.swing.JFrame; 27 | import javax.swing.JLabel; 28 | import javax.swing.JPanel; 29 | import javax.swing.JRootPane; 30 | import javax.swing.JScrollPane; 31 | import javax.swing.JTable; 32 | import javax.swing.JTextArea; 33 | import javax.swing.SwingWorker; 34 | import javax.swing.border.EmptyBorder; 35 | import javax.swing.border.LineBorder; 36 | import javax.swing.filechooser.FileFilter; 37 | import javax.swing.plaf.DimensionUIResource; 38 | import javax.swing.table.TableCellRenderer; 39 | import javax.swing.table.TableColumn; 40 | import javax.swing.table.TableColumnModel; 41 | 42 | import com.mpatric.mp3agic.InvalidDataException; 43 | import com.mpatric.mp3agic.NotSupportedException; 44 | import com.mpatric.mp3agic.UnsupportedTagException; 45 | 46 | import at.dcosta.tonuino.cardadmin.CardFilesystemAnalyzer; 47 | import at.dcosta.tonuino.cardadmin.CardFilesystemAnalyzer.RequiredAction; 48 | import at.dcosta.tonuino.cardadmin.IndexGenerator; 49 | import at.dcosta.tonuino.cardadmin.Mp3Player; 50 | import at.dcosta.tonuino.cardadmin.Track; 51 | import at.dcosta.tonuino.cardadmin.TrackListener; 52 | import at.dcosta.tonuino.cardadmin.ui.ModalDialog.Duration; 53 | import at.dcosta.tonuino.cardadmin.util.Configuration; 54 | import at.dcosta.tonuino.cardadmin.util.ExceptionUtil; 55 | import at.dcosta.tonuino.cardadmin.util.FileNames; 56 | import at.dcosta.tonuino.cardadmin.util.StreamGobbler; 57 | import at.dcosta.tonuino.cardadmin.util.TrackSorter; 58 | 59 | public class FilesystemView implements DirectorySelectionListener, TrackListener, ActionListener, ErrorDisplay { 60 | 61 | private static final String CMD_NORMALIZE = "normalize"; 62 | private static final String CMD_SAVE_ID_TAGS = "saveIdTags"; 63 | private static final String CMD_PERSIST_TRACK_ORDER = "persistTrackOrder"; 64 | private JTable trackTable; 65 | private JFrame frame; 66 | private JScrollPane fileScrollPane; 67 | private TrackTableModel trackTableModel; 68 | private Mp3Player mp3Player; 69 | private JButton normalize; 70 | private JButton writeTags; 71 | private JButton persistTrackOrder; 72 | private JLabel errorSummary; 73 | private JTextArea errorDetail; 74 | private JPanel error; 75 | private File addFilesBaseDir; 76 | private File currentPath; 77 | private Path cardRoot; 78 | private JButton analyzeCardFilesystem; 79 | private JButton createCardIndex; 80 | 81 | public FilesystemView() { 82 | mp3Player = new Mp3Player(); 83 | addFilesBaseDir = Configuration.getInstance().getDefaultContentRoot(); 84 | } 85 | 86 | private JPanel createHeaderButtons(FolderTree folderTree) { 87 | JPanel headerPanel = new JPanel(); 88 | headerPanel.setBorder(new EmptyBorder(10, 5, 5, 5)); 89 | headerPanel.setLayout(new BorderLayout()); 90 | JButton newFolder = new JButton("Neuer Ordner"); 91 | newFolder.addActionListener(new ActionListener() { 92 | 93 | @Override 94 | public void actionPerformed(ActionEvent e) { 95 | File parent = folderTree.getCurrentFolder(); 96 | 97 | if (parent.getParentFile() != null && !Configuration.getInstance().isAlternativeCardRoot(parent)) { 98 | new ModalDialog().makeToast("Achtung", 99 | "An dieser Stelle kann kein neues Track-Verzeichnis erstellt werden!", frame, 100 | Duration.SHORT); 101 | return; 102 | } 103 | if (folderTree != null) { 104 | try { 105 | new File(parent, FileNames.getNextFolderName(parent)).mkdir(); 106 | folderTree.folderAdded(); 107 | } catch (IOException ex) { 108 | showError("Can not create new folder:", ex); 109 | } 110 | } 111 | } 112 | }); 113 | JButton addFiles = new JButton("Dateien hinzufügen"); 114 | addFiles.addActionListener(new ActionListener() { 115 | 116 | @Override 117 | public void actionPerformed(ActionEvent e) { 118 | File target = folderTree.getCurrentFolder(); 119 | if (target == null) { 120 | return; 121 | } 122 | final JFileChooser fc = new JFileChooser(); 123 | fc.setFileFilter(new FileFilter() { 124 | 125 | @Override 126 | public String getDescription() { 127 | return null; 128 | } 129 | 130 | @Override 131 | public boolean accept(File f) { 132 | return f.isDirectory() || f.getName().toLowerCase().endsWith(FileNames.SUFFIX_MP3); 133 | } 134 | }); 135 | fc.setCurrentDirectory(addFilesBaseDir); 136 | fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 137 | fc.setMultiSelectionEnabled(true); 138 | int returnVal = fc.showOpenDialog(frame); 139 | 140 | if (returnVal == JFileChooser.APPROVE_OPTION) { 141 | ModalDialog wait = new ModalDialog(); 142 | SwingWorker worker = new SwingWorker() { 143 | 144 | private String errorMessage = ""; 145 | private String errorDetail = ""; 146 | 147 | @Override 148 | protected Void doInBackground() throws Exception { 149 | Iterator targetFileNames = FileNames.getNextFileNames(target); 150 | for (File file : fc.getSelectedFiles()) { 151 | try { 152 | addFilesBaseDir = file.getParentFile(); 153 | Path source = file.toPath(); 154 | new Track(source) 155 | .writeTo(new File(target, targetFileNames.next()).getAbsolutePath(), true); 156 | } catch (Exception ex) { 157 | errorMessage += file.getName() + ": " + ex.getMessage() + "
\n"; 158 | errorDetail += file.getName() + ": " + ex.getMessage() + "\n" 159 | + ExceptionUtil.getStacktrace(ex) + "-------------------------\n\n"; 160 | } 161 | } 162 | return null; 163 | } 164 | 165 | protected void done() { 166 | wait.close(); 167 | update(target); 168 | if (errorMessage.length() > 0) { 169 | new ModalDialog().makeToast("Fehler!", "" + errorMessage + "", frame, 170 | Duration.LONG); 171 | showError("Fehler beim Datei-Import", errorDetail); 172 | } 173 | } 174 | 175 | }; 176 | worker.execute(); 177 | wait.showWait("Bitte warten", "Die Dateien werden importiert...", frame); 178 | } 179 | } 180 | }); 181 | 182 | JPanel p = new JPanel(); 183 | p.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); 184 | analyzeCardFilesystem = new JButton("SD-Karte analysieren"); 185 | analyzeCardFilesystem.setBorder(new EmptyBorder(new Insets(5, 5, 5, 5))); 186 | analyzeCardFilesystem.setEnabled(false); 187 | p.add(analyzeCardFilesystem); 188 | analyzeCardFilesystem.addActionListener(new ActionListener() { 189 | 190 | @Override 191 | public void actionPerformed(ActionEvent e) { 192 | if (!cardFilesystemSelected()) { 193 | return; 194 | } 195 | 196 | ModalDialog wait = new ModalDialog(); 197 | SwingWorker worker = new SwingWorker() { 198 | @Override 199 | protected Void doInBackground() throws Exception { 200 | Map changes = CardFilesystemAnalyzer.analyzeRoot(cardRoot); 201 | changes.putAll(CardFilesystemAnalyzer.correctFolders(cardRoot, true)); 202 | StringBuilder b = new StringBuilder(); 203 | if (changes.isEmpty()) { 204 | b.append("Es sind keine Änderungen an der SD-Karte nötig!"); 205 | } else { 206 | b.append("Folgende Änderungen an der SD-Karte sind nötig:\n\n"); 207 | b.append(CardFilesystemAnalyzer.toGermanText(changes)); 208 | } 209 | wait.close(); 210 | new MultilineTextDialog().show("Analyse-Ergebnis", b.toString(), frame); 211 | return null; 212 | } 213 | 214 | protected void done() { 215 | wait.close(); 216 | } 217 | 218 | }; 219 | worker.execute(); 220 | wait.showWait("Bitte warten", "Das Filesystem wird korrigiert...", frame); 221 | } 222 | 223 | }); 224 | 225 | createCardIndex = new JButton("SD-Karten-Index generieren"); 226 | createCardIndex.setBorder(new EmptyBorder(new Insets(5, 5, 5, 5))); 227 | createCardIndex.setEnabled(false); 228 | p.add(createCardIndex); 229 | createCardIndex.addActionListener(new ActionListener() { 230 | 231 | @Override 232 | public void actionPerformed(ActionEvent e) { 233 | if (!cardFilesystemSelected()) { 234 | return; 235 | } 236 | 237 | ModalDialog wait = new ModalDialog(); 238 | SwingWorker worker = new SwingWorker() { 239 | @Override 240 | protected Void doInBackground() throws Exception { 241 | new IndexGenerator(Configuration.getInstance().getIndexFormat()).createIndexfile(cardRoot); 242 | return null; 243 | } 244 | 245 | protected void done() { 246 | wait.close(); 247 | } 248 | 249 | }; 250 | worker.execute(); 251 | wait.showWait("Bitte warten", "Der Index wird generiert...", frame); 252 | } 253 | 254 | }); 255 | 256 | headerPanel.add(newFolder, BorderLayout.LINE_START); 257 | headerPanel.add(p, BorderLayout.CENTER); 258 | headerPanel.add(addFiles, BorderLayout.LINE_END); 259 | return headerPanel; 260 | } 261 | 262 | private boolean cardFilesystemSelected() { 263 | return cardRoot != null; 264 | } 265 | 266 | private void updateCardRoot() { 267 | analyzeCardFilesystem.setEnabled(false); 268 | createCardIndex.setEnabled(false); 269 | if (currentPath == null) { 270 | cardRoot = null; 271 | } 272 | File f = currentPath; 273 | Configuration config = Configuration.getInstance(); 274 | Path altRootPath; 275 | if (config.hasAlternativeCardRoot()) { 276 | altRootPath = Paths.get(config.getAlternativeCardRoot()); 277 | } else { 278 | altRootPath = null; 279 | } 280 | while (f != null && f.getParentFile() != null) { 281 | if (f.toPath().equals(altRootPath)) { 282 | break; 283 | } 284 | f = f.getParentFile(); 285 | } 286 | if (f == null) { 287 | cardRoot = null; 288 | return; 289 | } 290 | analyzeCardFilesystem.setEnabled(true); 291 | createCardIndex.setEnabled(true); 292 | cardRoot = f.toPath(); 293 | } 294 | 295 | private JPanel createFooterButtons() { 296 | JPanel footerPanel = new JPanel(); 297 | footerPanel.setBorder(new EmptyBorder(10, 5, 0, 5)); 298 | footerPanel.setLayout(new FlowLayout()); 299 | 300 | normalize = new JButton("Tracks normalisieren"); 301 | normalize.setActionCommand(CMD_NORMALIZE); 302 | normalize.setEnabled(Configuration.getInstance().hasNormalizer()); 303 | normalize.setEnabled(false); 304 | normalize.addActionListener(this); 305 | 306 | persistTrackOrder = new JButton("Reihenfolge übernehmen"); 307 | persistTrackOrder.setActionCommand(CMD_PERSIST_TRACK_ORDER); 308 | persistTrackOrder.addActionListener(this); 309 | persistTrackOrder.setEnabled(false); 310 | 311 | writeTags = new JButton("ID-Tags speichern"); 312 | writeTags.setActionCommand(CMD_SAVE_ID_TAGS); 313 | writeTags.addActionListener(this); 314 | writeTags.setEnabled(false); 315 | 316 | footerPanel.add(normalize); 317 | footerPanel.add(persistTrackOrder); 318 | footerPanel.add(writeTags); 319 | return footerPanel; 320 | } 321 | 322 | public void show() throws IOException { 323 | trackTableModel = new TrackTableModel(this); 324 | 325 | frame = new JFrame("Tonuino Card Admin"); 326 | frame.setLayout(new BorderLayout(5, 5)); 327 | 328 | JPanel filesPanel = new JPanel(); 329 | filesPanel.setLayout(new BoxLayout(filesPanel, BoxLayout.Y_AXIS)); 330 | trackTable = new JTable(trackTableModel); 331 | trackTable.setGridColor(Color.LIGHT_GRAY); 332 | trackTable.addMouseListener(new MouseAdapter() { 333 | @Override 334 | public void mouseClicked(MouseEvent e) { 335 | if (mp3Player.isPlaying()) { 336 | mp3Player.stop(); 337 | } 338 | Point point = e.getPoint(); 339 | int col = trackTable.columnAtPoint(point); 340 | int row = trackTable.rowAtPoint(point); 341 | Track track = trackTableModel.getTrackAtRow(row); 342 | if (col == 0) { 343 | mp3Player.play(track); 344 | } else if (col == 6) { 345 | persistTrackOrder.setEnabled(true); 346 | trackTableModel.move(row, e.getButton() == MouseEvent.BUTTON1 ? Direction.UP : Direction.FIRST); 347 | } else if (col == 7) { 348 | persistTrackOrder.setEnabled(true); 349 | trackTableModel.move(row, e.getButton() == MouseEvent.BUTTON1 ? Direction.DOWN : Direction.LAST); 350 | } 351 | } 352 | }); 353 | 354 | trackTable.getTableHeader().addMouseListener(new MouseAdapter() { 355 | @Override 356 | public void mouseClicked(MouseEvent e) { 357 | if (e.getClickCount() == 2) { 358 | int column = trackTable.columnAtPoint(e.getPoint()); 359 | trackTableModel.sort(column); 360 | persistTrackOrder.setEnabled(true); 361 | } 362 | } 363 | }); 364 | 365 | trackTable.setRowSelectionAllowed(false); 366 | fileScrollPane = new JScrollPane(trackTable); 367 | 368 | trackTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 369 | 370 | filesPanel.add(fileScrollPane); 371 | filesPanel.add(createFooterButtons()); 372 | 373 | final FolderTree folderTree = new FolderTree(300, (int) filesPanel.getPreferredSize().getHeight(), this); 374 | frame.add(folderTree, BorderLayout.LINE_START); 375 | 376 | frame.add(createHeaderButtons(folderTree), BorderLayout.NORTH); 377 | frame.add(filesPanel, BorderLayout.CENTER); 378 | createErrorDisplay(); 379 | frame.add(error, BorderLayout.SOUTH); 380 | frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); 381 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 382 | frame.pack(); 383 | frame.setVisible(true); 384 | frame.setIconImage( 385 | new ImageIcon(TrackTableModel.class.getClassLoader().getResource("images/card-admin.png")).getImage()); 386 | 387 | update(null); 388 | } 389 | 390 | private void createErrorDisplay() { 391 | error = new JPanel(); 392 | error.setBorder(new LineBorder(Color.BLACK)); 393 | error.setLayout(new BoxLayout(error, BoxLayout.Y_AXIS)); 394 | error.setAlignmentX(Component.LEFT_ALIGNMENT); 395 | errorSummary = new JLabel(); 396 | errorSummary.setForeground(Color.RED); 397 | error.add(errorSummary); 398 | error.add(new JLabel("")); 399 | errorDetail = new JTextArea(); 400 | errorDetail.setFont(new Font("Tahoma", Font.PLAIN, 10)); 401 | errorDetail.setEditable(false); 402 | errorDetail.setBackground(errorSummary.getBackground()); 403 | errorDetail.setBorder(new EmptyBorder(new Insets(1, 1, 1, 1))); 404 | JScrollPane scrollPane = new JScrollPane(errorDetail); 405 | error.add(scrollPane); 406 | error.addMouseListener(new MouseAdapter() { 407 | @Override 408 | public void mouseClicked(MouseEvent e) { 409 | if (e.getButton() != MouseEvent.BUTTON1) { 410 | error.setVisible(false); 411 | frame.pack(); 412 | } 413 | } 414 | }); 415 | error.setVisible(false); 416 | error.setPreferredSize(new DimensionUIResource(frame.getWidth(), 100)); 417 | } 418 | 419 | private void update(File path) { 420 | currentPath = path; 421 | updateCardRoot(); 422 | persistTrackOrder.setEnabled(false); 423 | writeTags.setEnabled(false); 424 | ModalDialog wait = new ModalDialog(); 425 | frame.pack(); 426 | SwingWorker worker = new SwingWorker() { 427 | @Override 428 | protected Void doInBackground() throws Exception { 429 | if (path != null) { 430 | trackTableModel.update(path, FilesystemView.this); 431 | } 432 | int totalWidth = 0; 433 | final TableColumnModel columnModel = trackTable.getColumnModel(); 434 | for (int column = 0; column < trackTable.getColumnCount(); column++) { 435 | int width = 30; // Min width 436 | for (int row = 0; row < trackTable.getRowCount(); row++) { 437 | TableCellRenderer renderer = trackTable.getCellRenderer(row, column); 438 | Component comp = trackTable.prepareRenderer(renderer, row, column); 439 | width = Math.max(comp.getPreferredSize().width + 5, width); 440 | if (width > 300) { 441 | break; 442 | } 443 | } 444 | // header 445 | TableColumn col = trackTable.getColumnModel().getColumn(column); 446 | TableCellRenderer renderer = col.getHeaderRenderer(); 447 | if (renderer == null) { 448 | renderer = trackTable.getTableHeader().getDefaultRenderer(); 449 | } 450 | width = Math.max(width, renderer 451 | .getTableCellRendererComponent(trackTable, col.getHeaderValue(), false, false, -1, column) 452 | .getPreferredSize().width); 453 | if (width > 300) { 454 | width = 300; 455 | } 456 | columnModel.getColumn(column).setPreferredWidth(width); 457 | totalWidth += width; 458 | } 459 | frame.pack(); 460 | fileScrollPane.setPreferredSize(new DimensionUIResource(totalWidth, 400)); 461 | error.setPreferredSize(new DimensionUIResource(totalWidth, 100)); 462 | return null; 463 | } 464 | 465 | protected void done() { 466 | wait.close(); 467 | normalize.setEnabled(!trackTableModel.getTracks().isEmpty() && Configuration.getInstance().hasNormalizer()); 468 | } 469 | 470 | }; 471 | worker.execute(); 472 | wait.showWait("Bitte warten", "Das Verzeichnis wird gelesen...", frame); 473 | frame.pack(); 474 | } 475 | 476 | @Override 477 | public void pathSelected(File path) { 478 | update(path); 479 | } 480 | 481 | @Override 482 | public void trackChanged(Track track) { 483 | writeTags.setEnabled(true); 484 | } 485 | 486 | @Override 487 | public void actionPerformed(ActionEvent e) { 488 | final List tracks = trackTableModel.getTracks(); 489 | if (tracks.isEmpty()) { 490 | return; 491 | } 492 | if (e.getActionCommand() == CMD_SAVE_ID_TAGS) { 493 | writeTags.setEnabled(false); 494 | ModalDialog wait = new ModalDialog(); 495 | SwingWorker worker = new SwingWorker() { 496 | @Override 497 | protected Void doInBackground() throws Exception { 498 | tracks.forEach(t -> { 499 | try { 500 | t.save(); 501 | } catch (UnsupportedTagException | InvalidDataException | NotSupportedException 502 | | IOException ex) { 503 | showError("Can not save ID-Tags", ex); 504 | } 505 | }); 506 | return null; 507 | } 508 | 509 | protected void done() { 510 | wait.close(); 511 | } 512 | 513 | }; 514 | worker.execute(); 515 | wait.showWait("Bitte warten", "Die ID-Tags werden gespeichert...", frame); 516 | } else if (e.getActionCommand() == CMD_PERSIST_TRACK_ORDER) { 517 | persistTrackOrder.setEnabled(false); 518 | ModalDialog wait = new ModalDialog(); 519 | SwingWorker worker = new SwingWorker() { 520 | @Override 521 | protected Void doInBackground() throws Exception { 522 | TrackSorter.correctFilenames(tracks, FilesystemView.this); 523 | return null; 524 | } 525 | 526 | protected void done() { 527 | wait.close(); 528 | } 529 | }; 530 | worker.execute(); 531 | wait.showWait("Bitte warten", "Die Dateien werden umsortiert...", frame); 532 | update(tracks.get(0).getPath().getParent().toFile()); 533 | } else if (e.getActionCommand() == CMD_NORMALIZE) { 534 | List command = Configuration.getInstance().getNormalizerCommand(); 535 | for (Track track : trackTableModel.getTracks()) { 536 | command.add(track.getPath().toString()); 537 | } 538 | 539 | ModalDialog dialog = new ModalDialog(); 540 | SwingWorker worker = new SwingWorker() { 541 | @Override 542 | protected Void doInBackground() throws Exception { 543 | ProcessBuilder builder = new ProcessBuilder(); 544 | builder.command(command); 545 | try { 546 | Process process = builder.start(); 547 | StreamGobbler in = new StreamGobbler(process.getInputStream()); 548 | StreamGobbler err = new StreamGobbler(process.getErrorStream()).setUpdateableDialog(dialog); 549 | SwingWorker worker2 = new SwingWorker() { 550 | @Override 551 | protected Void doInBackground() throws Exception { 552 | in.run(); 553 | return null; 554 | } 555 | }; 556 | SwingWorker worker3 = new SwingWorker() { 557 | @Override 558 | protected Void doInBackground() throws Exception { 559 | err.run(); 560 | return null; 561 | } 562 | }; 563 | worker2.execute(); 564 | worker3.execute(); 565 | try { 566 | process.waitFor(); 567 | } catch (InterruptedException e) { 568 | // ignore 569 | } 570 | } catch (Exception ex) { 571 | showError("Error normalizing tracks", ex); 572 | } 573 | return null; 574 | } 575 | 576 | protected void done() { 577 | dialog.close(); 578 | normalize.setEnabled(false); 579 | } 580 | }; 581 | worker.execute(); 582 | dialog.showWait("Die Dateien werden normalisiert", "Bitte warten...", frame); 583 | } 584 | } 585 | 586 | @Override 587 | public void showError(String summary, Throwable t) { 588 | showError(summary, ExceptionUtil.getStacktrace(t)); 589 | } 590 | 591 | @Override 592 | public void showError(String summary, String detail) { 593 | errorSummary.setText(summary); 594 | errorDetail.setText(detail); 595 | error.setVisible(true); 596 | frame.pack(); 597 | } 598 | 599 | } 600 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/ui/FolderTree.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.ui; 2 | 3 | import java.awt.Color; 4 | import java.awt.Component; 5 | import java.awt.Dimension; 6 | import java.awt.Graphics; 7 | import java.io.File; 8 | import java.util.Vector; 9 | 10 | import javax.swing.BoxLayout; 11 | import javax.swing.Icon; 12 | import javax.swing.JLabel; 13 | import javax.swing.JOptionPane; 14 | import javax.swing.JPanel; 15 | import javax.swing.JScrollPane; 16 | import javax.swing.JTree; 17 | import javax.swing.SwingUtilities; 18 | import javax.swing.UIManager; 19 | import javax.swing.event.TreeExpansionEvent; 20 | import javax.swing.event.TreeExpansionListener; 21 | import javax.swing.event.TreeSelectionEvent; 22 | import javax.swing.event.TreeSelectionListener; 23 | import javax.swing.tree.DefaultMutableTreeNode; 24 | import javax.swing.tree.DefaultTreeModel; 25 | import javax.swing.tree.TreeCellRenderer; 26 | import javax.swing.tree.TreePath; 27 | import javax.swing.tree.TreeSelectionModel; 28 | 29 | public class FolderTree extends JPanel { 30 | private static final long serialVersionUID = 1L; 31 | 32 | protected JTree m_tree; 33 | protected DefaultTreeModel m_model; 34 | protected File currentFolder; 35 | private DefaultMutableTreeNode currentNode; 36 | private DirectorySelectionListener directorySelectionListener; 37 | 38 | public FolderTree(int width, int height, DirectorySelectionListener directorySelectionListener) { 39 | this.directorySelectionListener = directorySelectionListener; 40 | DefaultMutableTreeNode top = new DefaultMutableTreeNode("Computer"); 41 | 42 | DefaultMutableTreeNode node; 43 | File[] roots = File.listRoots(); 44 | for (int k = 0; k < roots.length; k++) { 45 | node = new DefaultMutableTreeNode(new FileNode(roots[k])); 46 | top.add(node); 47 | node.add(new DefaultMutableTreeNode(Boolean.TRUE)); 48 | } 49 | 50 | m_model = new DefaultTreeModel(top); 51 | m_tree = new JTree(m_model); 52 | 53 | m_tree.putClientProperty("JTree.lineStyle", "Angled"); 54 | 55 | TreeCellRenderer renderer = new IconCellRenderer(); 56 | m_tree.setCellRenderer(renderer); 57 | 58 | m_tree.addTreeExpansionListener(new DirExpansionListener()); 59 | 60 | m_tree.addTreeSelectionListener(new DirSelectionListener()); 61 | 62 | m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 63 | m_tree.setShowsRootHandles(true); 64 | m_tree.setEditable(false); 65 | 66 | JScrollPane s = new JScrollPane(); 67 | s.getViewport().add(m_tree); 68 | s.setPreferredSize(new Dimension(width, height)); 69 | setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 70 | add(s); 71 | } 72 | 73 | public File getCurrentFolder() { 74 | return currentFolder; 75 | } 76 | 77 | public void folderAdded() { 78 | currentNode.removeAllChildren(); 79 | currentNode.add(new DefaultMutableTreeNode(Boolean.TRUE)); 80 | getFileNode(currentNode).expand(currentNode); 81 | Thread runner = new Thread() { 82 | public void run() { 83 | Runnable runnable = new Runnable() { 84 | public void run() { 85 | m_model.reload(currentNode); 86 | } 87 | }; 88 | SwingUtilities.invokeLater(runnable); 89 | } 90 | }; 91 | runner.start(); 92 | } 93 | 94 | DefaultMutableTreeNode getTreeNode(TreePath path) { 95 | return (DefaultMutableTreeNode) (path.getLastPathComponent()); 96 | } 97 | 98 | FileNode getFileNode(DefaultMutableTreeNode node) { 99 | if (node == null) { 100 | return null; 101 | } 102 | Object obj = node.getUserObject(); 103 | if (obj instanceof FileNode) { 104 | return (FileNode) obj; 105 | } else { 106 | return null; 107 | } 108 | } 109 | 110 | // Make sure expansion is threaded and updating the tree model 111 | // only occurs within the event dispatching thread. 112 | class DirExpansionListener implements TreeExpansionListener { 113 | public void treeExpanded(TreeExpansionEvent event) { 114 | final DefaultMutableTreeNode node = getTreeNode(event.getPath()); 115 | currentNode = node; 116 | final FileNode fnode = getFileNode(node); 117 | 118 | Thread runner = new Thread() { 119 | public void run() { 120 | if (fnode != null && fnode.expand(node)) { 121 | Runnable runnable = new Runnable() { 122 | public void run() { 123 | m_model.reload(node); 124 | } 125 | }; 126 | SwingUtilities.invokeLater(runnable); 127 | } 128 | } 129 | }; 130 | runner.start(); 131 | } 132 | 133 | public void treeCollapsed(TreeExpansionEvent event) { 134 | } 135 | } 136 | 137 | class DirSelectionListener implements TreeSelectionListener { 138 | public void valueChanged(TreeSelectionEvent event) { 139 | DefaultMutableTreeNode node = getTreeNode(event.getPath()); 140 | currentNode = node; 141 | FileNode fnode = getFileNode(node); 142 | if (fnode != null) { 143 | directorySelectionListener.pathSelected(fnode.getFile()); 144 | currentFolder = fnode.getFile(); 145 | } 146 | } 147 | } 148 | } 149 | 150 | class IconCellRenderer extends JLabel implements TreeCellRenderer { 151 | private static final long serialVersionUID = 1L; 152 | protected Color m_textSelectionColor; 153 | protected Color m_textNonSelectionColor; 154 | protected Color m_bkSelectionColor; 155 | protected Color m_bkNonSelectionColor; 156 | protected Color m_borderSelectionColor; 157 | 158 | protected boolean m_selected; 159 | 160 | public IconCellRenderer() { 161 | super(); 162 | m_textSelectionColor = UIManager.getColor("Tree.selectionForeground"); 163 | m_textNonSelectionColor = UIManager.getColor("Tree.textForeground"); 164 | m_bkSelectionColor = UIManager.getColor("Tree.selectionBackground"); 165 | m_bkNonSelectionColor = UIManager.getColor("Tree.textBackground"); 166 | m_borderSelectionColor = UIManager.getColor("Tree.selectionBorderColor"); 167 | setOpaque(false); 168 | } 169 | 170 | public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, 171 | int row, boolean hasFocus) { 172 | DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; 173 | Object obj = node.getUserObject(); 174 | setText(obj.toString()); 175 | 176 | if (obj instanceof Boolean) { 177 | setText("Retrieving data..."); 178 | } 179 | 180 | setFont(tree.getFont()); 181 | setForeground(sel ? m_textSelectionColor : m_textNonSelectionColor); 182 | setBackground(sel ? m_bkSelectionColor : m_bkNonSelectionColor); 183 | m_selected = sel; 184 | return this; 185 | } 186 | 187 | public void paintComponent(Graphics g) { 188 | Color bColor = getBackground(); 189 | Icon icon = getIcon(); 190 | 191 | g.setColor(bColor); 192 | int offset = 0; 193 | if (icon != null && getText() != null) 194 | offset = (icon.getIconWidth() + getIconTextGap()); 195 | g.fillRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1); 196 | 197 | if (m_selected) { 198 | g.setColor(m_borderSelectionColor); 199 | g.drawRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1); 200 | } 201 | super.paintComponent(g); 202 | } 203 | } 204 | 205 | class FileNode { 206 | protected File m_file; 207 | 208 | public FileNode(File file) { 209 | m_file = file; 210 | } 211 | 212 | public File getFile() { 213 | return m_file; 214 | } 215 | 216 | public String toString() { 217 | return m_file.getName().length() > 0 ? m_file.getName() : m_file.getPath(); 218 | } 219 | 220 | public boolean expand(DefaultMutableTreeNode parent) { 221 | DefaultMutableTreeNode flag = (DefaultMutableTreeNode) parent.getFirstChild(); 222 | if (flag == null) { // No flag 223 | return false; 224 | } 225 | Object obj = flag.getUserObject(); 226 | if (!(obj instanceof Boolean)) { 227 | return false; // Already expanded 228 | } 229 | 230 | parent.removeAllChildren(); // Remove Flag 231 | 232 | File[] files = listFiles(); 233 | if (files == null) { 234 | return true; 235 | } 236 | 237 | Vector v = new Vector<>(); 238 | 239 | for (int k = 0; k < files.length; k++) { 240 | File f = files[k]; 241 | if (!(f.isDirectory())) { 242 | continue; 243 | } 244 | 245 | FileNode newNode = new FileNode(f); 246 | 247 | boolean isAdded = false; 248 | for (int i = 0; i < v.size(); i++) { 249 | FileNode nd = (FileNode) v.elementAt(i); 250 | if (newNode.compareTo(nd) < 0) { 251 | v.insertElementAt(newNode, i); 252 | isAdded = true; 253 | break; 254 | } 255 | } 256 | if (!isAdded) { 257 | v.addElement(newNode); 258 | } 259 | } 260 | 261 | for (int i = 0; i < v.size(); i++) { 262 | FileNode nd = (FileNode) v.elementAt(i); 263 | DefaultMutableTreeNode node = new DefaultMutableTreeNode(nd); 264 | parent.add(node); 265 | 266 | if (nd.hasSubDirs()) { 267 | node.add(new DefaultMutableTreeNode(Boolean.TRUE)); 268 | } 269 | } 270 | return true; 271 | } 272 | 273 | public boolean hasSubDirs() { 274 | File[] files = listFiles(); 275 | if (files == null) 276 | return false; 277 | for (int k = 0; k < files.length; k++) { 278 | if (files[k].isDirectory()) 279 | return true; 280 | } 281 | return false; 282 | } 283 | 284 | public int compareTo(FileNode toCompare) { 285 | return m_file.getName().compareToIgnoreCase(toCompare.m_file.getName()); 286 | } 287 | 288 | protected File[] listFiles() { 289 | if (!m_file.isDirectory()) 290 | return null; 291 | try { 292 | return m_file.listFiles(); 293 | } catch (Exception ex) { 294 | JOptionPane.showMessageDialog(null, "Error reading directory " + m_file.getAbsolutePath(), "Warning", 295 | JOptionPane.WARNING_MESSAGE); 296 | return null; 297 | } 298 | } 299 | } 300 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/ui/ModalDialog.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.ui; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Component; 5 | import java.awt.Dialog; 6 | import java.awt.Font; 7 | import java.awt.Insets; 8 | import java.awt.Window; 9 | 10 | import javax.swing.JDialog; 11 | import javax.swing.JLabel; 12 | import javax.swing.JPanel; 13 | import javax.swing.JProgressBar; 14 | import javax.swing.SwingUtilities; 15 | import javax.swing.SwingWorker; 16 | import javax.swing.border.EmptyBorder; 17 | 18 | import at.dcosta.tonuino.cardadmin.UpdateableDialog; 19 | 20 | public class ModalDialog implements UpdateableDialog { 21 | 22 | public enum Duration { 23 | SHORT(3000), LONG(6000); 24 | 25 | private final long millis; 26 | 27 | private Duration(long millis) { 28 | this.millis = millis; 29 | } 30 | 31 | public long getMillis() { 32 | return millis; 33 | } 34 | } 35 | 36 | private JDialog dialog; 37 | private JLabel msgLabel; 38 | private boolean disposed; 39 | 40 | public void showWait(String title, String message, Component parent) { 41 | show(title, message, parent, true); 42 | } 43 | 44 | public void showDialog(String title, String message, Component parent) { 45 | show(title, message, parent, false); 46 | } 47 | 48 | public void makeToast(String title, String message, Component parent, Duration duration) { 49 | SwingWorker worker = new SwingWorker() { 50 | 51 | @Override 52 | protected Void doInBackground() throws Exception { 53 | Thread.sleep(duration.getMillis()); 54 | return null; 55 | } 56 | 57 | protected void done() { 58 | close(); 59 | }; 60 | }; 61 | worker.execute(); 62 | show(title, message, parent, false); 63 | } 64 | 65 | private void show(String title, String message, Component parent, boolean withProgressBar) { 66 | Window win = SwingUtilities.getWindowAncestor(parent); 67 | dialog = new JDialog(win, title, Dialog.ModalityType.APPLICATION_MODAL); 68 | 69 | JPanel panel = new JPanel(new BorderLayout()); 70 | if (withProgressBar) { 71 | JProgressBar progressBar = new JProgressBar(); 72 | progressBar.setIndeterminate(true); 73 | panel.add(progressBar, BorderLayout.CENTER); 74 | } 75 | msgLabel = new JLabel(message); 76 | msgLabel.setBorder(new EmptyBorder(new Insets(5, 5, 5, 5))); 77 | msgLabel.setFont(new Font("Tahoma", Font.PLAIN, 14)); 78 | panel.add(msgLabel, BorderLayout.PAGE_START); 79 | dialog.add(panel); 80 | dialog.pack(); 81 | dialog.setLocationRelativeTo(parent); 82 | dialog.setVisible(true); 83 | } 84 | 85 | public void close() { 86 | if (!disposed) { 87 | disposed = true; 88 | dialog.dispose(); 89 | } 90 | } 91 | 92 | @Override 93 | public void updateText(String newText) { 94 | double oldWidth = msgLabel.getPreferredSize().getWidth(); 95 | msgLabel.setText(newText); 96 | double diff = msgLabel.getPreferredSize().getWidth() - oldWidth; 97 | if (newText.trim().length() > 0 && (diff > 10 || diff < -50)) { 98 | dialog.pack(); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/ui/MultilineTextDialog.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.ui; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Component; 5 | import java.awt.Dialog; 6 | import java.awt.Font; 7 | import java.awt.Insets; 8 | import java.awt.Window; 9 | import java.awt.event.ActionEvent; 10 | import java.awt.event.ActionListener; 11 | 12 | import javax.swing.JButton; 13 | import javax.swing.JDialog; 14 | import javax.swing.JPanel; 15 | import javax.swing.JScrollPane; 16 | import javax.swing.JTextArea; 17 | import javax.swing.SwingUtilities; 18 | import javax.swing.border.EmptyBorder; 19 | 20 | public class MultilineTextDialog { 21 | 22 | public void show(String title, String message, Component parent) { 23 | Window win = SwingUtilities.getWindowAncestor(parent); 24 | JDialog dialog = new JDialog(win, title, Dialog.ModalityType.APPLICATION_MODAL); 25 | 26 | JPanel panel = new JPanel(new BorderLayout()); 27 | JTextArea textArea = new JTextArea(); 28 | textArea.setText(message); 29 | textArea.setFont(new Font("Tahoma", Font.PLAIN, 12)); 30 | textArea.setEditable(false); 31 | textArea.setBorder(new EmptyBorder(new Insets(1, 1, 1, 1))); 32 | JScrollPane scrollPane = new JScrollPane(textArea); 33 | scrollPane.setBorder(new EmptyBorder(new Insets(10, 10, 10, 10))); 34 | panel.add(scrollPane, BorderLayout.PAGE_START); 35 | JButton button = new JButton("OK"); 36 | button.addActionListener(new ActionListener() { 37 | 38 | @Override 39 | public void actionPerformed(ActionEvent e) { 40 | dialog.dispose(); 41 | 42 | } 43 | }); 44 | panel.add(button, BorderLayout.LINE_START); 45 | dialog.add(panel); 46 | dialog.pack(); 47 | dialog.setLocationRelativeTo(parent); 48 | dialog.setVisible(true); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/ui/TableHeader.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.ui; 2 | 3 | import java.io.Serializable; 4 | 5 | public class TableHeader implements Serializable { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private final String name; 10 | private final ValueAdapter valueAdapter; 11 | 12 | public TableHeader(String name, ValueAdapter valueAdapter) { 13 | this.name = name; 14 | this.valueAdapter = valueAdapter; 15 | } 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | public ValueAdapter getValueAdapter() { 21 | return valueAdapter; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/ui/TrackTableModel.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.ui; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.nio.file.Files; 6 | import java.nio.file.Path; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.stream.Collectors; 10 | 11 | import javax.swing.ImageIcon; 12 | import javax.swing.table.AbstractTableModel; 13 | 14 | import com.mpatric.mp3agic.InvalidDataException; 15 | import com.mpatric.mp3agic.UnsupportedTagException; 16 | 17 | import at.dcosta.tonuino.cardadmin.Track; 18 | import at.dcosta.tonuino.cardadmin.TrackListener; 19 | import at.dcosta.tonuino.cardadmin.util.FileNames; 20 | import at.dcosta.tonuino.cardadmin.util.TrackSorter; 21 | 22 | public class TrackTableModel extends AbstractTableModel { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | private static final int MIN_EDIT_VALUE = 2; 27 | private static final int MAX_EDIT_VALUE = 5; 28 | 29 | private static final ImageIcon ICON_PLAY = new ImageIcon( 30 | TrackTableModel.class.getClassLoader().getResource("images/play.png")); 31 | private static final ImageIcon ICON_UP = new ImageIcon( 32 | TrackTableModel.class.getClassLoader().getResource("images/up.png")); 33 | private static final ImageIcon ICON_DOWN = new ImageIcon( 34 | TrackTableModel.class.getClassLoader().getResource("images/down.png")); 35 | 36 | private static TableHeader EMPTY_HEADER = new TableHeader("", new ValueAdapter() { 37 | private static final long serialVersionUID = 1L; 38 | 39 | @Override 40 | public Void getValue(Track track) { 41 | return null; 42 | } 43 | 44 | public void setValue(Void value, Track track) { 45 | }; 46 | }); 47 | 48 | private final List header; 49 | private final ErrorDisplay errorDisplay; 50 | private List tracks; 51 | 52 | public TrackTableModel(ErrorDisplay errorDisplay) { 53 | this.header = new ArrayList<>(); 54 | this.errorDisplay = errorDisplay; 55 | this.tracks = new ArrayList(); 56 | createHeader(); 57 | } 58 | 59 | public void update(File folder, TrackListener trackListener) throws IOException { 60 | this.tracks = Files.list(folder.toPath()) 61 | .filter(file -> file.getFileName().toString().toLowerCase().endsWith(FileNames.SUFFIX_MP3)) 62 | .map(file -> { 63 | try { 64 | return new Track(file).setTrackListener(trackListener); 65 | } catch (UnsupportedTagException | InvalidDataException | IOException e) { 66 | errorDisplay.showError("Can not read Tracks:", e); 67 | return null; 68 | } 69 | }).filter(track -> track != null).collect(Collectors.toList()); 70 | TrackSorter.sortByFilename(this.tracks); 71 | fireTableDataChanged(); 72 | } 73 | 74 | @SuppressWarnings("serial") 75 | private void createHeader() { 76 | header.add(EMPTY_HEADER); 77 | header.add(new TableHeader("File", new ValueAdapter() { 78 | @Override 79 | public Path getValue(Track track) { 80 | return track.getPath().getFileName(); 81 | } 82 | 83 | public void setValue(Path value, Track track) { 84 | }; 85 | })); 86 | header.add(new TableHeader("Album", new ValueAdapter() { 87 | @Override 88 | public String getValue(Track track) { 89 | return track.getAlbum(); 90 | } 91 | 92 | public void setValue(String value, Track track) { 93 | track.setAlbum(value); 94 | }; 95 | })); 96 | header.add(new TableHeader("Artist", new ValueAdapter() { 97 | @Override 98 | public String getValue(Track track) { 99 | return track.getArtist(); 100 | } 101 | 102 | public void setValue(String value, Track track) { 103 | track.setArtist(value); 104 | }; 105 | })); 106 | header.add(new TableHeader("Titel", new ValueAdapter() { 107 | @Override 108 | public String getValue(Track track) { 109 | return track.getTitle(); 110 | } 111 | 112 | public void setValue(String value, Track track) { 113 | track.setTitle(value); 114 | }; 115 | })); 116 | header.add(new TableHeader("Nr.", new ValueAdapter() { 117 | @Override 118 | public Integer getValue(Track track) { 119 | return track.getTrackNumber(); 120 | } 121 | 122 | public void setValue(Integer value, Track track) { 123 | track.setTrackNumber(value); 124 | }; 125 | })); 126 | header.add(EMPTY_HEADER); 127 | header.add(EMPTY_HEADER); 128 | 129 | } 130 | 131 | @Override 132 | public String getColumnName(int column) { 133 | return header.get(column).getName(); 134 | } 135 | 136 | @Override 137 | public int getRowCount() { 138 | return tracks.size(); 139 | } 140 | 141 | @Override 142 | public int getColumnCount() { 143 | return header.size(); 144 | } 145 | 146 | @Override 147 | public Class getColumnClass(int column) { 148 | switch (column) { 149 | case 0: 150 | case 6: 151 | case 7: 152 | return ImageIcon.class; 153 | default: 154 | return String.class; 155 | } 156 | } 157 | 158 | public Track getTrackAtRow(int row) { 159 | return tracks.get(row); 160 | } 161 | 162 | public void sort(int column) { 163 | TrackSorter.sort(this.tracks, header.get(column).getValueAdapter()); 164 | fireTableDataChanged(); 165 | } 166 | 167 | @Override 168 | public Object getValueAt(int rowIndex, int columnIndex) { 169 | if (columnIndex == 0) { 170 | return ICON_PLAY; 171 | } 172 | if (columnIndex == 6) { 173 | return ICON_UP; 174 | } 175 | if (columnIndex == 7) { 176 | return ICON_DOWN; 177 | } 178 | if (rowIndex < tracks.size() && columnIndex < header.size()) { 179 | ValueAdapter valueAdapter = header.get(columnIndex).getValueAdapter(); 180 | return valueAdapter.getValue(tracks.get(rowIndex)); 181 | } 182 | 183 | return null; 184 | } 185 | 186 | public List getTracks() { 187 | return tracks; 188 | } 189 | 190 | @SuppressWarnings("unchecked") 191 | @Override 192 | public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 193 | if (columnIndex == 5) { 194 | ValueAdapter valueAdapter = (ValueAdapter) header.get(columnIndex).getValueAdapter(); 195 | valueAdapter.setValue(aValue == null ? null : Integer.valueOf((String) aValue), tracks.get(rowIndex)); 196 | } else { 197 | ValueAdapter valueAdapter = (ValueAdapter) header.get(columnIndex).getValueAdapter(); 198 | valueAdapter.setValue((String) aValue, tracks.get(rowIndex)); 199 | } 200 | } 201 | 202 | @Override 203 | public boolean isCellEditable(int rowIndex, int columnIndex) { 204 | return columnIndex >= MIN_EDIT_VALUE && columnIndex <= MAX_EDIT_VALUE; 205 | } 206 | 207 | 208 | public void move(int rowId, Direction direction) { 209 | if (direction == Direction.UP || direction == Direction.DOWN) { 210 | int newPos = rowId + (direction == Direction.UP ? -1 : 1); 211 | 212 | if (newPos < 0 || newPos >= tracks.size()) { 213 | return; 214 | } 215 | Track tmp = tracks.get(newPos); 216 | tracks.set(newPos, tracks.get(rowId)); 217 | tracks.set(rowId, tmp); 218 | if (direction == Direction.UP) { 219 | fireTableRowsUpdated(newPos, rowId); 220 | } else { 221 | fireTableRowsUpdated(rowId, newPos); 222 | } 223 | } else { 224 | if (direction == Direction.FIRST) { 225 | Track tmp = tracks.get(rowId); 226 | for (int i = rowId; i > 0; i--) { 227 | tracks.set(i, tracks.get(i - 1)); 228 | } 229 | tracks.set(0, tmp); 230 | fireTableRowsUpdated(0, rowId); 231 | } else { 232 | Track tmp = tracks.get(rowId); 233 | for (int i = rowId; i < tracks.size() - 1; i++) { 234 | tracks.set(i, tracks.get(i + 1)); 235 | } 236 | tracks.set(tracks.size() - 1, tmp); 237 | fireTableRowsUpdated(rowId, tracks.size() - 1); 238 | } 239 | } 240 | } 241 | 242 | } 243 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/ui/ValueAdapter.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.ui; 2 | 3 | import at.dcosta.tonuino.cardadmin.Track; 4 | 5 | public interface ValueAdapter extends ValueResolver { 6 | 7 | void setValue(T value, Track track); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/ui/ValueResolver.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.ui; 2 | 3 | import java.io.Serializable; 4 | 5 | import at.dcosta.tonuino.cardadmin.Track; 6 | 7 | public interface ValueResolver extends Serializable { 8 | 9 | T getValue(Track track); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/util/Configuration.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.util; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.nio.file.Path; 8 | import java.nio.file.Paths; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.Properties; 12 | 13 | import at.dcosta.tonuino.cardadmin.IndexGenerator.IndexFormat; 14 | 15 | public class Configuration { 16 | 17 | private static final String CONFIGURATION_PROPERTIES = "configuration.properties"; 18 | private Properties props; 19 | 20 | private Configuration() { 21 | String cfgfilePath = System.getenv("cardAdminConfigFile"); 22 | InputStream in = null; 23 | try { 24 | if (cfgfilePath != null && new File(cfgfilePath).exists()) { 25 | in = new FileInputStream(new File(cfgfilePath)); 26 | } else { 27 | String exeDir = System.getProperty("launch4j.exedir"); 28 | if (exeDir != null) { 29 | File f = new File(exeDir, CONFIGURATION_PROPERTIES); 30 | if (f.exists()) { 31 | in = new FileInputStream(f); 32 | } 33 | } 34 | if (in == null) { 35 | in = getClass().getClassLoader().getResourceAsStream(CONFIGURATION_PROPERTIES); 36 | } 37 | } 38 | props = new Properties(); 39 | if (in != null) { 40 | props.load(in); 41 | } 42 | } catch (IOException ex) { 43 | ex.printStackTrace(); 44 | } finally { 45 | try { 46 | if (in != null) { 47 | in.close(); 48 | } 49 | } catch (Exception e) { 50 | e.printStackTrace(); 51 | // ignore 52 | } 53 | } 54 | } 55 | 56 | private static Configuration INSTANCE; 57 | static { 58 | INSTANCE = new Configuration(); 59 | } 60 | 61 | public static Configuration getInstance() { 62 | return INSTANCE; 63 | } 64 | 65 | public boolean hasNormalizer() { 66 | return getNormalizer() != null; 67 | } 68 | 69 | public boolean hasAlternativeCardRoot() { 70 | return getAlternativeCardRoot() != null; 71 | } 72 | 73 | private String getNormalizer() { 74 | return props.getProperty("mp3.normalizing.commandline"); 75 | } 76 | 77 | public String getCardIndexLocation() { 78 | return props.getProperty("card-index.location"); 79 | } 80 | 81 | public IndexFormat getIndexFormat() { 82 | String format = props.getProperty("card-index.format"); 83 | if ("csv".equalsIgnoreCase(format)) { 84 | return IndexFormat.CSV; 85 | } 86 | return IndexFormat.HUMAN_READABLE; 87 | } 88 | 89 | public List getNormalizerCommand() { 90 | List cmd = new ArrayList<>(); 91 | cmd.add(getNormalizer()); 92 | for (String option : getNormalizerOptions()) { 93 | cmd.add(option); 94 | } 95 | return cmd; 96 | } 97 | 98 | private String[] getNormalizerOptions() { 99 | return props.getProperty("mp3.normalizing.options").split("\\s"); 100 | } 101 | 102 | public String getAlternativeCardRoot() { 103 | String aRoot = props.getProperty("alternative.card.root"); 104 | return aRoot == null ? null : aRoot.trim(); 105 | } 106 | 107 | public File getDefaultContentRoot() { 108 | String aRoot = props.getProperty("default.content.root"); 109 | return aRoot == null ? null : new File(aRoot.trim()); 110 | } 111 | 112 | public boolean isAlternativeCardRoot(File f) { 113 | String alternativeCardRoot = getAlternativeCardRoot(); 114 | if (alternativeCardRoot == null) { 115 | return false; 116 | } 117 | Path altPath = Paths.get(alternativeCardRoot); 118 | Path filePath = f.toPath(); 119 | return filePath.equals(altPath); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/util/ExceptionUtil.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.util; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.PrintStream; 5 | 6 | public class ExceptionUtil { 7 | 8 | public static String getStacktrace(Throwable t) { 9 | ByteArrayOutputStream bout = new ByteArrayOutputStream(); 10 | try (PrintStream ps = new PrintStream(bout)) { 11 | t.printStackTrace(ps); 12 | ps.flush(); 13 | } 14 | return new String (bout.toByteArray()); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/util/FileNames.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.util; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.nio.file.Files; 6 | import java.nio.file.Path; 7 | import java.nio.file.Paths; 8 | import java.util.Calendar; 9 | import java.util.Date; 10 | import java.util.HashSet; 11 | import java.util.Iterator; 12 | import java.util.List; 13 | import java.util.Set; 14 | import java.util.regex.Pattern; 15 | import java.util.stream.Collectors; 16 | 17 | public final class FileNames { 18 | 19 | public enum Type { 20 | FILE(255, 1000, Pattern.compile("^((00[1-9])|([1-9]\\d\\d)|(\\d[1-9]\\d)).mp3$", Pattern.CASE_INSENSITIVE)), 21 | FOLDER(99, 100, Pattern.compile("^((0[1-9])|([1-9]\\d))$")); 22 | 23 | private final int maxValue; 24 | private final int toAdd; 25 | private Pattern pattern; 26 | 27 | private Type(int maxValue, int toAdd, Pattern pattern) { 28 | this.maxValue = maxValue; 29 | this.toAdd = toAdd; 30 | this.pattern = pattern; 31 | } 32 | 33 | public int getMaxValue() { 34 | return maxValue; 35 | } 36 | 37 | public int getToAdd() { 38 | return toAdd; 39 | } 40 | 41 | public Pattern getPattern() { 42 | return pattern; 43 | } 44 | } 45 | 46 | public static final String SUFFIX_MP3 = ".mp3"; 47 | 48 | public static final Set SYSTEM_FOLDERS; 49 | 50 | static { 51 | SYSTEM_FOLDERS = new HashSet<>(); 52 | SYSTEM_FOLDERS.add("advert"); 53 | SYSTEM_FOLDERS.add("mp3"); 54 | } 55 | 56 | public static String getNextFolderName(File parentFolder) throws IOException { 57 | return getNextNumber(parentFolder, Type.FOLDER); 58 | } 59 | 60 | public static String createDateFileName(String prefix, String suffix) { 61 | Calendar cal = Calendar.getInstance(); 62 | cal.setTime(new Date()); 63 | StringBuilder b = new StringBuilder(prefix); 64 | b.append('_'); 65 | b.append(toFixedDigitString(cal.get(Calendar.YEAR), 4)); 66 | b.append(toFixedDigitString(1 + cal.get(Calendar.MONTH), 2)); 67 | b.append(toFixedDigitString(cal.get(Calendar.DAY_OF_MONTH), 2)); 68 | b.append('_'); 69 | b.append(toFixedDigitString(cal.get(Calendar.HOUR_OF_DAY), 2)); 70 | b.append(toFixedDigitString(cal.get(Calendar.MINUTE), 4)); 71 | b.append(toFixedDigitString(cal.get(Calendar.SECOND), 4)); 72 | b.append(suffix); 73 | return b.toString(); 74 | } 75 | 76 | public static String toFixedDigitString(int val, int digits) { 77 | return Integer.toString(val + (int) Math.pow(10, digits)).substring(1); 78 | } 79 | 80 | public static String getNextFileNumber(File parentFolder) throws IOException { 81 | return getNextNumber(parentFolder, Type.FILE); 82 | } 83 | 84 | public static String getNextNumber(File parentFolder, Type type) throws IOException { 85 | List files = Files.list(parentFolder.toPath()) 86 | .filter(path -> type.getPattern().matcher(path.getFileName().toString()).matches()).sorted() 87 | .collect(Collectors.toList()); 88 | int highestExisting; 89 | if (files.size() > 0) { 90 | String lastFileName = files.get(files.size() - 1).getFileName().toString(); 91 | highestExisting = Integer 92 | .parseInt(lastFileName.substring(0, Integer.toString(type.getToAdd()).length() - 1)); 93 | } else { 94 | highestExisting = 0; 95 | } 96 | int newNumber = 1 + highestExisting; 97 | if (newNumber <= type.getMaxValue()) { 98 | return Integer.toString(type.getToAdd() + newNumber).substring(1); 99 | } 100 | throw new IllegalArgumentException("Too many files/folders!"); 101 | } 102 | 103 | public static Iterator createNewFileNameSeries(Path parent) { 104 | return new Iterator() { 105 | int i = 1; 106 | 107 | @Override 108 | public boolean hasNext() { 109 | return i <= Type.FILE.getMaxValue(); 110 | } 111 | 112 | @Override 113 | public Path next() { 114 | if (i <= Type.FILE.getMaxValue()) { 115 | String fileName = Integer.toString(1000 + i++).substring(1); 116 | return Paths.get(parent.toString(), fileName + SUFFIX_MP3); 117 | } 118 | throw new IllegalArgumentException("Too many files!"); 119 | } 120 | }; 121 | } 122 | 123 | public static Iterator getNextFileNames(File parentFolder) throws IOException { 124 | final int base = Integer.parseInt(getNextFileNumber(parentFolder)); 125 | return new Iterator() { 126 | int i = base; 127 | 128 | @Override 129 | public boolean hasNext() { 130 | return i <= Type.FILE.getMaxValue(); 131 | } 132 | 133 | @Override 134 | public String next() { 135 | if (i <= Type.FILE.getMaxValue()) { 136 | return Integer.toString(1000 + i++).substring(1) + SUFFIX_MP3; 137 | } 138 | throw new IllegalArgumentException("Too many files!"); 139 | } 140 | }; 141 | } 142 | 143 | public static int getFileNumber(Path path) { 144 | String name = path.getFileName().toString(); 145 | if (!name.toLowerCase().endsWith(SUFFIX_MP3)) { 146 | throw new IllegalArgumentException("FileName does not have suffix " + SUFFIX_MP3); 147 | } 148 | return Integer.parseInt(name.substring(0, name.length() - SUFFIX_MP3.length())); 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/util/LogUtil.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.util; 2 | 3 | import java.lang.System.Logger; 4 | import java.lang.System.Logger.Level; 5 | import java.util.Arrays; 6 | 7 | public class LogUtil { 8 | 9 | public static final void debug(Logger logger, Object...message) { 10 | log(logger, Level.DEBUG, message); 11 | } 12 | 13 | public static final void error(Logger logger, Object...message) { 14 | log(logger, Level.ERROR, message); 15 | } 16 | 17 | public static final void info(Logger logger, Object...message) { 18 | log(logger, Level.INFO, message); 19 | } 20 | 21 | public static final void trace(Logger logger, Object...message) { 22 | log(logger, Level.TRACE, message); 23 | } 24 | 25 | public static final void log(Logger logger, Level level, Object...message) { 26 | if (logger.isLoggable(level)) { 27 | StringBuilder b = new StringBuilder(); 28 | Arrays.stream(message).forEach(s -> b.append(s)); 29 | logger.log(level, b.toString()); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/util/StreamGobbler.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.util; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStream; 5 | import java.io.InputStreamReader; 6 | 7 | import at.dcosta.tonuino.cardadmin.UpdateableDialog; 8 | 9 | public class StreamGobbler implements Runnable { 10 | private InputStream inputStream; 11 | private StringBuilder content; 12 | private UpdateableDialog updateableDialog; 13 | 14 | public StreamGobbler(InputStream inputStream) { 15 | this.inputStream = inputStream; 16 | this.content = new StringBuilder(); 17 | } 18 | 19 | public StreamGobbler setUpdateableDialog(UpdateableDialog updateableDialog) { 20 | this.updateableDialog = updateableDialog; 21 | return this; 22 | } 23 | 24 | @Override 25 | public void run() { 26 | new BufferedReader(new InputStreamReader(inputStream)).lines().forEach(l -> { 27 | if (updateableDialog != null) { 28 | updateableDialog.updateText(l); 29 | } 30 | content.append(l); 31 | }); 32 | } 33 | 34 | public String getContent() { 35 | return content.toString(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /card-admin/src/main/java/at/dcosta/tonuino/cardadmin/util/TrackSorter.java: -------------------------------------------------------------------------------- 1 | package at.dcosta.tonuino.cardadmin.util; 2 | 3 | import java.io.IOException; 4 | import java.lang.System.Logger; 5 | import java.nio.file.Files; 6 | import java.nio.file.Path; 7 | import java.nio.file.Paths; 8 | import java.util.Comparator; 9 | import java.util.HashMap; 10 | import java.util.Iterator; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | import at.dcosta.tonuino.cardadmin.Track; 15 | import at.dcosta.tonuino.cardadmin.ui.ErrorDisplay; 16 | import at.dcosta.tonuino.cardadmin.ui.ValueResolver; 17 | 18 | public class TrackSorter { 19 | 20 | private static final Logger LOGGER = System.getLogger(TrackSorter.class.getName()); 21 | 22 | public static void correctFilenames(List tracks, ErrorDisplay errorDisplay) { 23 | if (tracks.isEmpty()) { 24 | return; 25 | } 26 | Map renames = new HashMap<>(); 27 | Iterator newPaths = FileNames.createNewFileNameSeries(tracks.get(0).getPath().getParent()); 28 | tracks.forEach(t -> { 29 | Path newPath = newPaths.next(); 30 | LogUtil.trace(LOGGER, "path: ", t.getPath(), " - should be: ", newPath); 31 | if (!newPath.equals(t.getPath())) { 32 | Path tmpPath = Paths.get(t.getPath().toString() + ".tmp"); 33 | try { 34 | Files.move(t.getPath(), tmpPath); 35 | LogUtil.debug(LOGGER, "rename1: ", t.getPath(), " -> ", tmpPath); 36 | } catch (IOException e) { 37 | errorDisplay.showError("Can not rename tracks", e); 38 | } 39 | renames.put(tmpPath, newPath); 40 | } 41 | }); 42 | renames.entrySet().forEach(e -> { 43 | try { 44 | Files.move(e.getKey(), e.getValue()); 45 | LogUtil.debug(LOGGER, "rename2: ", e.getKey(), " -> ", e.getValue()); 46 | } catch (IOException ex) { 47 | errorDisplay.showError("Can not rename tracks", ex); 48 | } 49 | }); 50 | } 51 | 52 | public static void sortByFilename(List tracks) { 53 | tracks.sort(new Comparator() { 54 | 55 | @Override 56 | public int compare(Track t1, Track t2) { 57 | return t1.getPath().toString().compareTo(t2.getPath().toString()); 58 | } 59 | }); 60 | } 61 | 62 | public static void sort(List tracks, ValueResolver valueResolver) { 63 | tracks.sort(new Comparator() { 64 | 65 | @Override 66 | public int compare(Track t1, Track t2) { 67 | return valueResolver.getValue(t1).toString().compareTo(valueResolver.getValue(t2).toString()); 68 | } 69 | }); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /card-admin/src/main/resources/configuration.properties: -------------------------------------------------------------------------------- 1 | # normalizing program 2 | # if not set, no normalizing can be done 3 | mp3.normalizing.commandline=C:\\Program Files (x86)\\MP3Gain\\mp3gain.exe 4 | mp3.normalizing.options = /a /k 5 | 6 | # alternative card-roots 7 | # i.e. for using a local folder as card-backup 8 | alternative.card.root = D:/media/Tonuino/SD-Karte 9 | #alternative.card.root = D:/media/Tonuino/test 10 | 11 | # default content root 12 | default.content.root = D:/media/Tonuino/Content 13 | 14 | # index file location 15 | card-index.location = D:/media/Tonuino/SD-Karten-Index 16 | # set to csv to generate csv files 17 | # any other string (or no value) will generate human readable files 18 | card-index.format = csv -------------------------------------------------------------------------------- /card-admin/src/main/resources/images/card-admin.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coschtl/tonuino-cardadmin/8ad9699ba7f6cae11c3661730f64d41f7fd2cc06/card-admin/src/main/resources/images/card-admin.ico -------------------------------------------------------------------------------- /card-admin/src/main/resources/images/card-admin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coschtl/tonuino-cardadmin/8ad9699ba7f6cae11c3661730f64d41f7fd2cc06/card-admin/src/main/resources/images/card-admin.png -------------------------------------------------------------------------------- /card-admin/src/main/resources/images/card-admin.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coschtl/tonuino-cardadmin/8ad9699ba7f6cae11c3661730f64d41f7fd2cc06/card-admin/src/main/resources/images/card-admin.xcf -------------------------------------------------------------------------------- /card-admin/src/main/resources/images/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coschtl/tonuino-cardadmin/8ad9699ba7f6cae11c3661730f64d41f7fd2cc06/card-admin/src/main/resources/images/down.png -------------------------------------------------------------------------------- /card-admin/src/main/resources/images/play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coschtl/tonuino-cardadmin/8ad9699ba7f6cae11c3661730f64d41f7fd2cc06/card-admin/src/main/resources/images/play.png -------------------------------------------------------------------------------- /card-admin/src/main/resources/images/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coschtl/tonuino-cardadmin/8ad9699ba7f6cae11c3661730f64d41f7fd2cc06/card-admin/src/main/resources/images/up.png -------------------------------------------------------------------------------- /card-admin/src/main/resources/launch4j.cfg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | false 4 | gui 5 | D:\development\data\git\TonUINO\cardadmin\card-admin\target\card-admin-0.3.0.jar 6 | C:\Users\Stephan\Desktop\TonuinoCardAdmin.exe 7 | 8 | 9 | . 10 | normal 11 | http://java.com/download 12 | 13 | true 14 | false 15 | 16 | D:\development\data\git\TonUINO\cardadmin\card-admin\src\main\resources\images\card-admin.ico 17 | 18 | 19 | false 20 | false 21 | 1.8 22 | 23 | preferJre 24 | 64/32 25 | -Denv.cardadminconfigfile="%cardAdminConfigFile%" 26 | -Dlaunch4j.exedir="%EXEDIR%" 27 | 28 | -------------------------------------------------------------------------------- /card-admin/src/main/resources/start.cmd: -------------------------------------------------------------------------------- 1 | rem @echo off 2 | if not defined java_location ( 3 | set java_location=D:\development\apps\jdk1.8.0_201 4 | ) 5 | 6 | rem ######################################################## 7 | 8 | %java_location%\bin\java.exe at.dcosta.tonuino.cardadmin.Main %1 %2 %3 %4 -------------------------------------------------------------------------------- /card-admin/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | card-admin 7 | https://maven.apache.org/images/apache-maven-project.png 8 | https://www.apache.org/ 9 | 10 | 11 | 12 | https://maven.apache.org/images/maven-logo-black-on-white.png 13 | https://maven.apache.org/ 14 | 15 | 16 | 17 | org.apache.maven.skins 18 | maven-fluido-skin 19 | 1.7 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coschtl/tonuino-cardadmin/8ad9699ba7f6cae11c3661730f64d41f7fd2cc06/screenshot.png --------------------------------------------------------------------------------