~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpinstall/packager/win_gre/GetLongFile.pl

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!c:\perl\bin\perl
 
2
 
3
# The contents of this file are subject to the Mozilla Public
 
4
# License Version 1.1 (the "License"); you may not use this file
 
5
# except in compliance with the License. You may obtain a copy of
 
6
# the License at http://www.mozilla.org/MPL/
 
7
 
8
# Software distributed under the License is distributed on an "AS
 
9
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
# implied. See the License for the specific language governing
 
11
# rights and limitations under the License.
 
12
 
13
# The Original Code is Mozilla Navigator.
 
14
 
15
# The Initial Developer of the Original Code is Netscape Communications
 
16
# Corp.  Portions created by Netscape Communications Corp. are
 
17
# Copyright (C) 1998, 1999, 2000, 2001 Netscape Communications Corp.  All
 
18
# Rights Reserved.
 
19
 
20
# Contributor(s):
 
21
#   Sean Su <ssu@netscape.com>
 
22
 
23
 
 
24
use Cwd;
 
25
 
 
26
if($#ARGV < 1)
 
27
{
 
28
    print_usage();
 
29
    exit(1);
 
30
}
 
31
 
 
32
print "searching for longfilenames in:\n";
 
33
print "  $ARGV[0]\n";
 
34
 
 
35
$outFile     = $ARGV[1];
 
36
$start_dir   = $ARGV[0];
 
37
$start_dir   =~ s/\\/\//g;
 
38
 
 
39
if(substr($start_dir, -1, 1) ne '/')
 
40
{
 
41
    $start_dir = $start_dir . "/";
 
42
}
 
43
 
 
44
($MOZ_TOOLS = $ENV{"MOZ_TOOLS"}) =~ s/\\/\//g;
 
45
 
 
46
# Open the output file
 
47
open(fpOutFile, ">>$outFile") || die "\nCould not open $outFile: $!\n";
 
48
 
 
49
# $rv has the following possible values:
 
50
#   0 - Found at least one long filename file
 
51
#   1 - Error locating GetShortPathName.exe
 
52
#   2 - No long filename file found
 
53
$rv = check_dir_structure($ARGV[0]);
 
54
 
 
55
print "\n";
 
56
close(fpOutFile);
 
57
exit($rv);
 
58
# end
 
59
 
 
60
sub check_dir_structure
 
61
{
 
62
    my($curr_dir) = @_;
 
63
    my($foundFirstFile) = 2; # This var is also used as a return value:
 
64
                             #   0 - Found at least one long filename file
 
65
                             #   1 - Error locating GetShortPathName.exe
 
66
                             #   2 - No long filename file found
 
67
 
 
68
    $save_cwd     = cwd();
 
69
    $save_cwd     =~ s/\\/\//g;
 
70
    if((-e "$curr_dir") && (-d "$curr_dir"))
 
71
    {
 
72
        $foundFirstFile = check_all_dir($curr_dir, $foundFirstFile);
 
73
        chdir($save_cwd);
 
74
        print " done!";
 
75
    }
 
76
    else
 
77
    {
 
78
        if(!(-e "$curr_dir"))
 
79
        {
 
80
            print "\n";
 
81
            print "$curr_dir does not exist!";
 
82
        }
 
83
        elsif(!(-d "$curr_dir"))
 
84
        {
 
85
            print "\n";
 
86
            print "$curr_dir is not a valid directory!";
 
87
        }
 
88
    }
 
89
 
 
90
    # print out the closing brace for the last file written out.
 
91
    if($foundFirstFile == 0)
 
92
    {
 
93
        # at least one file was found
 
94
        # print the "];\n" for the previous file found.
 
95
        print fpOutFile "];\n";
 
96
    }
 
97
 
 
98
    return($foundFirstFile);
 
99
}
 
100
 
 
101
sub check_all_dir
 
102
{
 
103
    my($curr_dir, $foundFirstFile) = @_;
 
104
    my(@dirlist);
 
105
    my($file);
 
106
 
 
107
    chdir("$curr_dir");
 
108
    @dirlist = <*>;
 
109
    foreach $file (@dirlist)
 
110
    {
 
111
        if(-d "$file")
 
112
        {
 
113
            print ".";
 
114
            $foundFirstFile = check_all_dir($file, $foundFirstFile);
 
115
        }
 
116
        elsif(-e $file)
 
117
        {
 
118
            if(check_extension($file))
 
119
            {
 
120
                $short_filename = `$MOZ_TOOLS/bin/GetShortPathName.exe $file`;
 
121
                if(($?/256) == 1)
 
122
                {
 
123
                    print "$MOZ_TOOLS/bin/GetShortPathName.exe: $!\n";
 
124
                    exit(1);
 
125
                }
 
126
 
 
127
                if(!($file =~ /$short_filename/i))
 
128
                {
 
129
                    if($foundFirstFile == 0)
 
130
                    {
 
131
                        # at least one file was found
 
132
                        # print the ",\n" for the previous file found.
 
133
                        print fpOutFile ",\n";
 
134
                    }
 
135
 
 
136
                    $curr_path = cwd();
 
137
                    # perl has problems dealing with '\\''s in split(), so we need to
 
138
                    # convert them to '/''s.
 
139
                    $curr_path =~ s/\\/\//g;
 
140
                    @relative_path = split(/$start_dir/,$curr_path);
 
141
                    if($relative_path[1] eq "")
 
142
                    {
 
143
                        print_file($file, $foundFirstFile);
 
144
                    }
 
145
                    else
 
146
                    {
 
147
                        print_file("$relative_path[1]/$file", $foundFirstFile);
 
148
                    }
 
149
                    $foundFirstFile = 0;
 
150
                }
 
151
            }
 
152
        }
 
153
    }
 
154
    chdir("..");
 
155
    return($foundFirstFile);
 
156
}
 
157
 
 
158
sub check_extension
 
159
{
 
160
  my($file)      = @_;
 
161
  my($var);
 
162
  @listExtension = ("dll",
 
163
                    "com",
 
164
                    "jar",
 
165
                    "exe");
 
166
 
 
167
  @arrayExtension = split(/\./,$file);
 
168
  $extension = @arrayExtension[$#arrayExtension];
 
169
  foreach $var (@listExtension)
 
170
  {
 
171
    if($extension eq $var)
 
172
    {
 
173
      return(1);
 
174
    }
 
175
  }
 
176
  return(0);
 
177
}
 
178
 
 
179
sub print_file
 
180
{
 
181
  my($file, $foundFirstFile) = @_;
 
182
 
 
183
  if($foundFirstFile)
 
184
  {
 
185
      # first file in list
 
186
      print fpOutFile "// This list contains filenames that are long filenames ( > 8.3) critical during installation time.\n";
 
187
      print fpOutFile "// This list is automatically generated during the build process.\n";
 
188
      print fpOutFile "// The filenames should include paths relative to the Netscape 6 folder.\n";
 
189
      print fpOutFile "// '/' must be used as path delimiters regardless of platform.\n";
 
190
      print fpOutFile "var listLongFilePaths = [\"$file\"";
 
191
  }
 
192
  else
 
193
  {
 
194
      # middle file in list
 
195
      print fpOutFile "                         \"$file\"";
 
196
  }
 
197
}
 
198
 
 
199
sub print_usage
 
200
{
 
201
    print "\n usage: $0 <dir> <outfile>\n";
 
202
    print "\n        dir     - full path to look for files\n";
 
203
    print "        outfile - file to append to\n";
 
204
}